✨ 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!
85 lines
2.3 KiB
PHP
85 lines
2.3 KiB
PHP
<?php
|
||
/**
|
||
* SSE endpoint с постоянным подключением
|
||
*/
|
||
|
||
// Настройки 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'); // Nginx: отключить буферизацию
|
||
|
||
// Отключаем буферизацию PHP
|
||
while (ob_get_level()) {
|
||
ob_end_clean();
|
||
}
|
||
|
||
// Отключаем лимит времени выполнения
|
||
set_time_limit(0);
|
||
ignore_user_abort(true);
|
||
|
||
// Функция для отправки SSE события
|
||
function sendSSEEvent($type, $data) {
|
||
$event = [
|
||
'type' => $type,
|
||
'data' => $data,
|
||
'timestamp' => time()
|
||
];
|
||
|
||
echo "data: " . json_encode($event) . "\n\n";
|
||
|
||
if (ob_get_level() > 0) {
|
||
ob_flush();
|
||
}
|
||
flush();
|
||
}
|
||
|
||
// Отправляем начальное событие
|
||
sendSSEEvent('connected', [
|
||
'message' => 'SSE подключение установлено',
|
||
'server_time' => date('Y-m-d H:i:s')
|
||
]);
|
||
|
||
// Основной цикл
|
||
$lastHeartbeat = time();
|
||
$heartbeatInterval = 30; // Heartbeat каждые 30 секунд
|
||
|
||
while (true) {
|
||
// Проверяем подключение
|
||
if (connection_aborted()) {
|
||
break;
|
||
}
|
||
|
||
// Отправляем heartbeat
|
||
if (time() - $lastHeartbeat >= $heartbeatInterval) {
|
||
sendSSEEvent('heartbeat', ['timestamp' => time()]);
|
||
$lastHeartbeat = time();
|
||
}
|
||
|
||
// Проверяем события из файла
|
||
$eventsFile = '/tmp/crm_sse_events.json';
|
||
|
||
if (file_exists($eventsFile) && filesize($eventsFile) > 0) {
|
||
$content = file_get_contents($eventsFile);
|
||
if (!empty($content)) {
|
||
$events = json_decode($content, true);
|
||
if ($events && is_array($events)) {
|
||
foreach ($events as $event) {
|
||
sendSSEEvent($event['type'], $event['data']);
|
||
}
|
||
// Очищаем файл после отправки
|
||
file_put_contents($eventsFile, '');
|
||
}
|
||
}
|
||
}
|
||
|
||
// Небольшая пауза, чтобы не нагружать процессор
|
||
usleep(500000); // 0.5 секунды
|
||
}
|
||
?>
|
||
|
||
|
||
|
||
|