From eecaf17542a7fc132893b2ca48f3e6096193dc1b Mon Sep 17 00:00:00 2001 From: Jean-Luc Cooke <1479371+jlcooke@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:56:06 -0400 Subject: [PATCH] isConnected() fix, also smarter use of spl_object_id() (#3) Co-authored-by: Jean-Luc Cooke --- src/Client.php | 10 ++++++---- src/Connection.php | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Client.php b/src/Client.php index 1cd1ffb..6078ca5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -355,11 +355,12 @@ protected function submitTask(Task $task) $s = $this->getConnection(); Connection::send($s, $type, $params); - if (!is_array(Connection::$waiting[spl_object_id($s)])) { - Connection::$waiting[spl_object_id($s)] = []; + $key = is_object($s) ? spl_object_id($s) : intval($s); + if (!is_array(Connection::$waiting[$key])) { + Connection::$waiting[$key] = []; } - Connection::$waiting[spl_object_id($s)][] = $task; + Connection::$waiting[$key][] = $task; } /** @@ -463,7 +464,8 @@ protected function handleResponse($resp, $s, Set $tasks) $task->fail(); break; case 'job_created': - $task = array_shift(Connection::$waiting[spl_object_id($s)]); + $key = is_object($s) ? spl_object_id($s) : intval($s); + $task = array_shift(Connection::$waiting[$key]); $task->handle = $resp['data']['handle']; if ($task->type == Task::JOB_BACKGROUND) { $task->finished = true; diff --git a/src/Connection.php b/src/Connection.php index f8062f3..de97a94 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -174,7 +174,8 @@ public static function connect($host = 'localhost', $timeout = 2000) ); } - self::$waiting[spl_object_id($socket)] = []; + $key = is_object($socket) ? spl_object_id($socket) : intval($socket); + self::$waiting[$key] = []; return $socket; } @@ -371,7 +372,7 @@ public static function close($socket) */ public static function isConnected($socket) { - return $conn !== false; + return $socket !== false; } /**