Files
crm.clientright.ru/crm_extensions/file_storage/api/redis_sse.php
Fedor 9245768987 🚀 CRM Files Migration & Real-time Features
 Features:
- Migrated ALL files to new S3 structure (Projects, Contacts, Accounts, HelpDesk, Invoice, etc.)
- Added Nextcloud folder buttons to ALL modules
- Fixed Nextcloud editor integration
- WebSocket server for real-time updates
- Redis Pub/Sub integration
- File path manager for organized storage
- Redis caching for performance (Functions.php)

📁 New Structure:
Documents/Project/ProjectName_ID/file_docID.ext
Documents/Contacts/FirstName_LastName_ID/file_docID.ext
Documents/Accounts/AccountName_ID/file_docID.ext

🔧 Technical:
- FilePathManager for standardized paths
- S3StorageService integration
- WebSocket server (Node.js + Docker)
- Redis cache for getBasicModuleInfo()
- Predis library for Redis connectivity

📝 Scripts:
- Migration scripts for all modules
- Test pages for WebSocket/SSE/Polling
- Documentation (MIGRATION_*.md, REDIS_*.md)

🎯 Result: 15,000+ files migrated successfully!
2025-10-24 19:59:28 +03:00

67 lines
1.7 KiB
PHP

<?php
/**
* SSE Subscriber: Redis → Browser
*
* Подписывается на Redis канал и отправляет события через SSE
*/
// Отключаем буферизацию
while (@ob_end_flush());
// Настройки SSE
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
header('Access-Control-Allow-Origin: *');
header('X-Accel-Buffering: no');
// Отключаем лимит времени
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
set_time_limit(0);
ignore_user_abort(false);
// Отправляем начальный padding для Nginx
echo str_repeat(' ', 4096);
echo "\n\n";
flush();
// Функция для отправки события
function send($type, $data) {
echo "data: " . json_encode([
'type' => $type,
'data' => $data,
'time' => date('H:i:s')
]) . "\n\n";
flush();
}
try {
// Подключаемся к Redis
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth('CRM_Redis_Pass_2025_Secure!');
// Отправляем начальное событие
send('connected', ['message' => 'Подключено к Redis']);
// Подписываемся на канал
$channel = 'crm:file:events';
$redis->subscribe([$channel], function($redis, $channel, $message) {
// Декодируем событие
$event = json_decode($message, true);
if ($event) {
// Отправляем событие клиенту
send($event['type'], $event['data']);
}
});
} catch (Exception $e) {
send('error', ['message' => 'Redis error: ' . $e->getMessage()]);
}
?>