Update: 2026-08-01 18:37:02
This commit is contained in:
@@ -57,6 +57,11 @@ class Database
|
|||||||
$user = getenv($cfg['user']);
|
$user = getenv($cfg['user']);
|
||||||
$pass = getenv($cfg['pass']);
|
$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) {
|
if (!$dbname || !$user) {
|
||||||
error_log("[FATAL] Database config missing for: $name (Check ENV keys: {$cfg['name']}, {$cfg['user']})");
|
error_log("[FATAL] Database config missing for: $name (Check ENV keys: {$cfg['name']}, {$cfg['user']})");
|
||||||
throw new RuntimeException("Database configuration error.");
|
throw new RuntimeException("Database configuration error.");
|
||||||
|
|||||||
@@ -53,12 +53,18 @@ try {
|
|||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
error_log("[get.php] api_get_nearby HTTP $httpCode | Response: $response");
|
||||||
|
|
||||||
$redisDrivers = [];
|
$redisDrivers = [];
|
||||||
if ($httpCode == 200 && $response) {
|
if ($httpCode == 200 && $response) {
|
||||||
$json = json_decode($response, true);
|
$json = json_decode($response, true);
|
||||||
if (isset($json['status']) && $json['status'] === true) {
|
if (isset($json['status']) && $json['status'] === true) {
|
||||||
$redisDrivers = $json['drivers'] ?? $json['data'] ?? [];
|
$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)) {
|
if (empty($redisDrivers)) {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ $headers = getallheaders();
|
|||||||
$receivedKey = $headers['x-internal-key'] ?? $_SERVER['HTTP_X_INTERNAL_KEY'] ?? '';
|
$receivedKey = $headers['x-internal-key'] ?? $_SERVER['HTTP_X_INTERNAL_KEY'] ?? '';
|
||||||
|
|
||||||
if (!empty($INTERNAL_KEY) && $receivedKey !== $INTERNAL_KEY) {
|
if (!empty($INTERNAL_KEY) && $receivedKey !== $INTERNAL_KEY) {
|
||||||
|
error_log("[api_get_nearby] Unauthorized: receivedKey ($receivedKey) != expectedKey ($INTERNAL_KEY)");
|
||||||
http_response_code(403);
|
http_response_code(403);
|
||||||
echo json_encode(['status' => false, 'msg' => 'Unauthorized']);
|
echo json_encode(['status' => false, 'msg' => 'Unauthorized']);
|
||||||
exit;
|
exit;
|
||||||
@@ -79,7 +80,15 @@ try {
|
|||||||
$profile = $redis->hgetall("driver:profile:$d_id");
|
$profile = $redis->hgetall("driver:profile:$d_id");
|
||||||
$lastUpdate = isset($profile['updated_at']) ? (int)$profile['updated_at'] : 0;
|
$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:available', $d_id);
|
||||||
$redis->zrem('geo:drivers:busy', $d_id);
|
$redis->zrem('geo:drivers:busy', $d_id);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -368,8 +368,10 @@ $io->on('workerStart', function () use ($io, $INTERNAL_KEY) {
|
|||||||
|
|
||||||
if ($st === 'off') {
|
if ($st === 'off') {
|
||||||
$pipe->geoadd('geo:drivers:available', $lng, $lat, $driverId);
|
$pipe->geoadd('geo:drivers:available', $lng, $lat, $driverId);
|
||||||
|
logMsg("[REDIS BATCH] Added Driver $driverId to geo:drivers:available at $lat, $lng");
|
||||||
} elseif ($st === 'on') {
|
} elseif ($st === 'on') {
|
||||||
$pipe->geoadd('geo:drivers:busy', $lng, $lat, $driverId);
|
$pipe->geoadd('geo:drivers:busy', $lng, $lat, $driverId);
|
||||||
|
logMsg("[REDIS BATCH] Added Driver $driverId to geo:drivers:busy at $lat, $lng");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -877,6 +879,8 @@ $io->on('connection', function ($socket) use ($INTERNAL_KEY) {
|
|||||||
$state = &$driverState[$driverId];
|
$state = &$driverState[$driverId];
|
||||||
$now = time();
|
$now = time();
|
||||||
|
|
||||||
|
logMsg("[SOCKET] update_location received for Driver $driverId | status=$status, lat=$lat, lng=$lng");
|
||||||
|
|
||||||
// 1. Forward للراكب (ASYNC + throttle)
|
// 1. Forward للراكب (ASYNC + throttle)
|
||||||
if (!empty($passengerId)) {
|
if (!empty($passengerId)) {
|
||||||
forwardLocationToPassengerSocket(
|
forwardLocationToPassengerSocket(
|
||||||
|
|||||||
Reference in New Issue
Block a user