Update: 2026-08-01 18:37:02

This commit is contained in:
Hamza-Ayed
2026-08-01 18:37:02 +03:00
parent f7df080b27
commit b30fe7e96d
4 changed files with 25 additions and 1 deletions
+10 -1
View File
@@ -31,6 +31,7 @@ $headers = getallheaders();
$receivedKey = $headers['x-internal-key'] ?? $_SERVER['HTTP_X_INTERNAL_KEY'] ?? '';
if (!empty($INTERNAL_KEY) && $receivedKey !== $INTERNAL_KEY) {
error_log("[api_get_nearby] Unauthorized: receivedKey ($receivedKey) != expectedKey ($INTERNAL_KEY)");
http_response_code(403);
echo json_encode(['status' => false, 'msg' => 'Unauthorized']);
exit;
@@ -79,7 +80,15 @@ try {
$profile = $redis->hgetall("driver:profile:$d_id");
$lastUpdate = isset($profile['updated_at']) ? (int)$profile['updated_at'] : 0;
if (empty($profile) || ($currentTime - $lastUpdate) > $max_silence) {
if (empty($profile)) {
error_log("[api_get_nearby] Driver $d_id skipped: profile is empty in Redis.");
$redis->zrem('geo:drivers:available', $d_id);
$redis->zrem('geo:drivers:busy', $d_id);
continue;
}
if (($currentTime - $lastUpdate) > $max_silence) {
error_log("[api_get_nearby] Driver $d_id skipped: lastUpdate ($lastUpdate) is older than max_silence ($max_silence).");
$redis->zrem('geo:drivers:available', $d_id);
$redis->zrem('geo:drivers:busy', $d_id);
continue;
+4
View File
@@ -368,8 +368,10 @@ $io->on('workerStart', function () use ($io, $INTERNAL_KEY) {
if ($st === 'off') {
$pipe->geoadd('geo:drivers:available', $lng, $lat, $driverId);
logMsg("[REDIS BATCH] Added Driver $driverId to geo:drivers:available at $lat, $lng");
} elseif ($st === 'on') {
$pipe->geoadd('geo:drivers:busy', $lng, $lat, $driverId);
logMsg("[REDIS BATCH] Added Driver $driverId to geo:drivers:busy at $lat, $lng");
}
}
}
@@ -876,6 +878,8 @@ $io->on('connection', function ($socket) use ($INTERNAL_KEY) {
$state = &$driverState[$driverId];
$now = time();
logMsg("[SOCKET] update_location received for Driver $driverId | status=$status, lat=$lat, lng=$lng");
// 1. Forward للراكب (ASYNC + throttle)
if (!empty($passengerId)) {