Files
crm.clientright.ru/crm_extensions/file_storage/api/redis_sse_simple.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

86 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* ПРОСТОЙ SSE: проверяет Redis ключи каждые 2 секунды
* Не использует SUBSCRIBE (который блокирует)
*/
// Отключаем буферизацию
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);
// Функция для отправки события
function send($type, $data) {
echo "data: " . json_encode([
'type' => $type,
'data' => $data,
'time' => date('H:i:s')
], JSON_UNESCAPED_UNICODE) . "\n\n";
flush();
}
try {
require_once '/var/www/fastuser/data/www/crm.clientright.ru/vendor/autoload.php';
// Создаем клиент Predis
$redis = new Predis\Client([
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379,
'password' => 'CRM_Redis_Pass_2025_Secure!',
]);
// Отправляем начальное событие
send('connected', ['message' => 'SSE подключен', 'timestamp' => time()]);
$lastCheck = '';
$eventCounter = 0;
// Бесконечный цикл
while (true) {
// Проверяем не отключился ли клиент
if (connection_aborted()) {
break;
}
// Проверяем список событий в Redis
$events = $redis->lrange('crm:file:events:queue', 0, -1);
if (!empty($events)) {
foreach ($events as $eventJson) {
$event = json_decode($eventJson, true);
if ($event) {
send($event['type'], $event['data']);
$eventCounter++;
}
}
// Очищаем обработанные события
$redis->del(['crm:file:events:queue']);
}
// Отправляем heartbeat каждые 15 секунд
if (time() % 15 == 0 && $lastCheck != time()) {
send('heartbeat', ['timestamp' => time(), 'events_processed' => $eventCounter]);
$lastCheck = time();
}
// Ждем 1 секунду перед следующей проверкой
sleep(1);
}
} catch (Exception $e) {
send('error', ['message' => $e->getMessage()]);
}