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

69 lines
1.9 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
/**
* Long Polling API для синхронизации файлов
*
* Ждет до 30 секунд, пока не появятся события
*/
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
// Отключаем буферизацию
while (ob_get_level()) {
ob_end_clean();
}
// Увеличиваем время выполнения
set_time_limit(35); // 30 сек ожидание + 5 сек запас
$eventsFile = '/tmp/crm_sse_events.json';
$timeout = 30; // Максимальное время ожидания в секундах
$checkInterval = 0.5; // Интервал проверки в секундах
$startTime = time();
$events = [];
// Ждем события или таймаута
while (time() - $startTime < $timeout) {
// Проверяем события с блокировкой
$fp = @fopen($eventsFile, 'c+');
if ($fp && flock($fp, LOCK_EX)) {
$content = stream_get_contents($fp);
if (!empty($content)) {
$events = json_decode($content, true) ?: [];
// Если есть события - очищаем файл и отправляем
if (!empty($events)) {
ftruncate($fp, 0);
flock($fp, LOCK_UN);
fclose($fp);
break; // Выходим из цикла
}
}
flock($fp, LOCK_UN);
fclose($fp);
}
// Пауза перед следующей проверкой
usleep($checkInterval * 1000000);
// Проверяем, не отключился ли клиент
if (connection_aborted()) {
exit;
}
}
// Отправляем ответ
echo json_encode([
'status' => 'success',
'events' => $events,
'timestamp' => time(),
'waited' => time() - $startTime
]);
?>