connect($redisHost, $redisPort, 1.5)) { if ($redisPass) $redis->auth($redisPass); $redis->setOption(Redis::OPT_PREFIX, 'siro:'); } else { $redis = null; } // --- Location Server Redis --- $redisLocation = new Redis(); // 🔥 [Fix Silent Fallback] إذا لم تُضبط REDIS_LOCATION_HOST صراحة، نسقط // على Redis الرئيسي — وهذا يجعل استعلامات كثافة السائقين (geo:drivers:*) // ترجع فارغة بصمت لأن تلك المفاتيح تُكتب فقط على Redis الخاص بلوكيشن // سيرفر. نسجّل تحذيراً واضحاً حتى لا يمر هذا دون ملاحظة في اللوجز. $locHostConfigured = getenv('REDIS_LOCATION_HOST'); if (!$locHostConfigured) { error_log('[REDIS] ⚠️ REDIS_LOCATION_HOST is not set — $redisLocation is falling back to the MAIN redis host (' . $redisHost . '). ' . 'geo:drivers:available / driver:profile:* / driver:public:* keys live only on the location-server Redis, ' . 'so driver-density lookups (getSpeed.php, heatmap_live.php, pricing/get.php) will silently return empty results ' . 'unless REDIS_LOCATION_HOST/PORT/PASSWORD are configured correctly in .env.'); } $locHost = $locHostConfigured ?: $redisHost; $locPort = (int)(getenv('REDIS_LOCATION_PORT') ?: $redisPort); $locPass = getenv('REDIS_LOCATION_PASSWORD') ?: $redisPass; if ($redisLocation->connect($locHost, $locPort, 1.5)) { if ($locPass) $redisLocation->auth($locPass); // No prefix for location server } else { error_log("[REDIS] ⚠️ Failed to connect \$redisLocation to $locHost:$locPort — driver-density features will be degraded."); $redisLocation = null; } } } catch (Throwable $e) { error_log("[REDIS] Connection failed: " . $e->getMessage()); $redis = null; $redisLocation = null; } // 5. تحميل الـ Services الأساسية require_once __DIR__ . '/Security/EncryptionHelper.php'; require_once __DIR__ . '/Security/BlindIndex.php'; // فهرس البحث الأعمى — اختياري: إن لم يُضبط BLIND_INDEX_PEPPER تبقى نقاط // البحث تعمل بأسلوبها القديم بدل أن تفشل. $blindIndex = null; try { $blindIndex = new BlindIndex(); } catch (Throwable $e) { error_log('[BlindIndex] disabled: ' . $e->getMessage()); } require_once __DIR__ . '/Database/Database.php'; require_once __DIR__ . '/Auth/RateLimiter.php'; require_once __DIR__ . '/Auth/JwtService.php'; // لا نحمّل OtpService و FcmService إلا عند الحاجة (Lazy) // 6. تهيئة Encryption Helper العام (للتوافقية) // يتم استخدام .enckey (32 بايت) لتشفير البيانات $encKeyPath = getenv('ENCRYPTION_KEY_PATH'); $encKey = ''; if ($encKeyPath && file_exists($encKeyPath)) { $encKey = trim(@file_get_contents($encKeyPath) ?: ''); } if (!$encKey) { $encKey = getenv('ENC_KEY') ?: ''; } if (!$encKey || strlen($encKey) !== 32) { error_log("[FATAL] Encryption key (.enckey) is missing or invalid length (must be 32 bytes)."); http_response_code(500); exit(json_encode(['error' => 'Server configuration error: Encryption key issue'])); } $encryptionHelper = new EncryptionHelper($encKey);