false, 'message' => 'Missing coordinates']); exit; } // 2. الاتصال بالريدز try { $redis = new Client([ 'scheme' => 'tcp', 'host' => '127.0.0.1','password' => $PASS_REDIS, 'port' => 6379, ]); $redis->connect(); } catch (Exception $e) { echo json_encode(['status' => false, 'message' => 'Redis Error']); exit; } // 3. البحث الجغرافي (السحر هنا) 🎩 // يبحث عن السائقين المتاحين (available) فقط // التعديل: تفعيل WITHDIST و SORT كـ مفاتيح $driversGeo = $redis->georadius( 'geo:drivers:available', $lng, $lat, $radius, 'km', ['WITHDIST' => true,'WITHCOORD' => true, 'COUNT' => $limit, 'SORT' => 'ASC'] ); // النتيجة تكون مصفوفة: [ [driver_id, distance], ... ] $resultDrivers = []; // 4. جلب التفاصيل if (!empty($driversGeo)) { foreach ($driversGeo as $item) { $driverId = $item[0]; $distance = $item[1]; // المسافة بالكيلومتر $d_coord= $item[2]; // [0=>lng, 1=>lat] 🔥 الإحداثيات هنا // جلب البيانات الوصفية من الرام (Profile) // هذه البيانات خزنها السوكيت قبل قليل $profile = $redis->hgetall("driver:profile:$driverId"); // دمج البيانات $resultDrivers[] = [ 'driver_id' => $driverId, 'distance_km' => $distance, 'heading' => $profile['heading'] ?? 0, 'speed' => $profile['speed'] ?? 0, 'status' => $profile['status'] ?? 'off', 'lat' => $d_coord[1], // Latitude من الريدز (أدق) 'lng' => $d_coord[0] // Longitude // يمكنك هنا إضافة استعلام MySQL بسيط لجلب اسم السائق وصورته إذا لم تكن مخزنة في الريدز // لكن للسرعة، سنكتفي بهذا الآن ]; } } // 5. إرجاع النتيجة echo json_encode([ 'status' => true, 'count' => count($resultDrivers), 'drivers' => $resultDrivers ]); ?>