Update: 2026-08-01 18:37:02
This commit is contained in:
@@ -57,6 +57,11 @@ class Database
|
||||
$user = getenv($cfg['user']);
|
||||
$pass = getenv($cfg['pass']);
|
||||
|
||||
// Fallback for missing ride table if intaleq-ridesDB is still configured
|
||||
if ($name === 'ride' && $dbname === 'intaleq-ridesDB') {
|
||||
$dbname = 'rideDB';
|
||||
}
|
||||
|
||||
if (!$dbname || !$user) {
|
||||
error_log("[FATAL] Database config missing for: $name (Check ENV keys: {$cfg['name']}, {$cfg['user']})");
|
||||
throw new RuntimeException("Database configuration error.");
|
||||
|
||||
@@ -52,13 +52,19 @@ try {
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
error_log("[get.php] api_get_nearby HTTP $httpCode | Response: $response");
|
||||
|
||||
$redisDrivers = [];
|
||||
if ($httpCode == 200 && $response) {
|
||||
$json = json_decode($response, true);
|
||||
if (isset($json['status']) && $json['status'] === true) {
|
||||
$redisDrivers = $json['drivers'] ?? $json['data'] ?? [];
|
||||
} else {
|
||||
error_log("[get.php] api_get_nearby returned error or false status. JSON: " . print_r($json, true));
|
||||
}
|
||||
} else {
|
||||
error_log("[get.php] api_get_nearby failed. HTTP Code: $httpCode");
|
||||
}
|
||||
|
||||
if (empty($redisDrivers)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user