From 41a2d711d18424f19d96414983666a694a625209 Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 26 Feb 2026 14:52:21 +0700 Subject: [PATCH 01/14] feat: added optional bigint to string conversion in client response --- docs/configuration.md | 4 +++- src/Manticoresearch/Client.php | 3 +++ src/Manticoresearch/Response.php | 17 ++++++++++++++++- src/Manticoresearch/Transport/Http.php | 4 ++++ src/Manticoresearch/Transport/PhpHttp.php | 4 ++++ 5 files changed, 30 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/Manticoresearch/Transport/PhpHttp.php diff --git a/docs/configuration.md b/docs/configuration.md index cd9f4cf..46ec8a2 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -53,6 +53,7 @@ Http/Https adapter options: * headers - array of custom headers * curl - array of CURL settings as option=>value * persistent - define whether the connection is persistent or not +* bigint_to_string - define whether big integers in response are converted to strings or not A simple example of multiple hosts: ``` @@ -92,7 +93,8 @@ A more advanced example where one host uses HTTP authentication and another requ 'curl' => [ CURLOPT_FAILONERROR => true ], - 'persistent' => true + 'persistent' => true, + 'bigint_to_string' => true, ], [ 'host' => '123.0.0.2', diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index e7727ed..657c873 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -400,6 +400,9 @@ public function explainQuery(array $params = []) { public function request(Request $request, array $params = [], string $retryReason = ''): Response { try { $connection = $this->connectionPool->getConnection($retryReason); + if (isset($this->config['bigint_to_string']) && $this->config['bigint_to_string']) { + $params['bigIntToString'] = true; + } $this->lastResponse = $connection->getTransportHandler($this->logger) ->execute($request, $params); if ($this->connectionPool->retriesAttempts) { diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index 35a64e9..e192c85 100644 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -54,6 +54,11 @@ class Response */ protected $params; + /** + * flag defining to apply or not bigint to string conversion + * @var bool + */ + protected $bigIntToString = false; public function __construct($responseString, $status = null, $params = []) { if (is_array($responseString)) { @@ -71,7 +76,9 @@ public function __construct($responseString, $status = null, $params = []) { */ public function getResponse() { if (null === $this->response) { - $this->response = json_decode($this->string, true); + $this->response = $this->bigIntToString + ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) + : json_decode($this->string, true); if (json_last_error() !== JSON_ERROR_NONE) { if (json_last_error() !== JSON_ERROR_UTF8 || !$this->stripBadUtf8()) { throw new RuntimeException( @@ -178,4 +185,12 @@ public function setTransportInfo($info) { public function getTransportInfo() { return $this->transportInfo; } + + /** + * @return void + */ + public function enableBigintConversion() { + $this->bigIntToString = true; + } + } diff --git a/src/Manticoresearch/Transport/Http.php b/src/Manticoresearch/Transport/Http.php index 98bcc82..37d8041 100644 --- a/src/Manticoresearch/Transport/Http.php +++ b/src/Manticoresearch/Transport/Http.php @@ -104,6 +104,10 @@ public function execute(Request $request, $params = []) { $response = new Response($responseString, $status); } + if (isset($params('bigIntToString'))) { + $response->enableBigintConversion(); + } + $time = $end - $start; $response->setTime($time); $response->setTransportInfo( diff --git a/src/Manticoresearch/Transport/PhpHttp.php b/src/Manticoresearch/Transport/PhpHttp.php old mode 100644 new mode 100755 index c95fa0f..a288819 --- a/src/Manticoresearch/Transport/PhpHttp.php +++ b/src/Manticoresearch/Transport/PhpHttp.php @@ -100,6 +100,10 @@ public function execute(Request $request, $params = []) { $response = new Response($responseString, $status); } + if (isset($params('bigIntToString'))) { + $response->enableBigintConversion(); + } + $time = $end - $start; $response->setTime($time); $response->setTransportInfo( From ddf544903c370ac41a2c55579d50e7b207606bea Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 26 Feb 2026 23:14:20 +0700 Subject: [PATCH 02/14] Fixed codestyle, fixed typo --- src/Manticoresearch/Response.php | 3 +++ src/Manticoresearch/Transport/Http.php | 4 ++-- src/Manticoresearch/Transport/PhpHttp.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/Manticoresearch/Response.php mode change 100644 => 100755 src/Manticoresearch/Transport/Http.php diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php old mode 100644 new mode 100755 index e192c85..735073a --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -76,9 +76,12 @@ public function __construct($responseString, $status = null, $params = []) { */ public function getResponse() { if (null === $this->response) { + $this->response = json_decode($this->string, true); + /* $this->response = $this->bigIntToString ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) : json_decode($this->string, true); + */ if (json_last_error() !== JSON_ERROR_NONE) { if (json_last_error() !== JSON_ERROR_UTF8 || !$this->stripBadUtf8()) { throw new RuntimeException( diff --git a/src/Manticoresearch/Transport/Http.php b/src/Manticoresearch/Transport/Http.php old mode 100644 new mode 100755 index 37d8041..4d52604 --- a/src/Manticoresearch/Transport/Http.php +++ b/src/Manticoresearch/Transport/Http.php @@ -104,8 +104,8 @@ public function execute(Request $request, $params = []) { $response = new Response($responseString, $status); } - if (isset($params('bigIntToString'))) { - $response->enableBigintConversion(); + if (isset($params['bigIntToString'])) { + $response->enableBigintConversion(); } $time = $end - $start; diff --git a/src/Manticoresearch/Transport/PhpHttp.php b/src/Manticoresearch/Transport/PhpHttp.php index a288819..e670d25 100755 --- a/src/Manticoresearch/Transport/PhpHttp.php +++ b/src/Manticoresearch/Transport/PhpHttp.php @@ -100,7 +100,7 @@ public function execute(Request $request, $params = []) { $response = new Response($responseString, $status); } - if (isset($params('bigIntToString'))) { + if (isset($params['bigIntToString'])) { $response->enableBigintConversion(); } From d278e781743032ebba89bd96bdbb9e837623390a Mon Sep 17 00:00:00 2001 From: nick80 Date: Mon, 2 Mar 2026 18:21:49 +0700 Subject: [PATCH 03/14] Updated tests to match changes in Manticore --- test/Manticoresearch/Endpoints/Nodes/VariablesTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Manticoresearch/Endpoints/Nodes/VariablesTest.php b/test/Manticoresearch/Endpoints/Nodes/VariablesTest.php index 31452a8..e8d1dfe 100644 --- a/test/Manticoresearch/Endpoints/Nodes/VariablesTest.php +++ b/test/Manticoresearch/Endpoints/Nodes/VariablesTest.php @@ -29,6 +29,7 @@ public function testVariables() { 'collation_connection', 'distinct_precision_threshold', 'grouping_in_utc', + 'interactive_timeout', 'last_insert_id', 'log_level', 'max_allowed_packet', @@ -42,6 +43,7 @@ public function testVariables() { 'threads_ex_effective', 'timezone', 'user', + 'wait_timeout', ], $keys ); } From 1d82cfdcc31baa520aa5dcd53b5b61c785e76b7e Mon Sep 17 00:00:00 2001 From: nick80 Date: Mon, 2 Mar 2026 19:11:40 +0700 Subject: [PATCH 04/14] Fixed typo --- src/Manticoresearch/Response.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index 735073a..e192c85 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -76,12 +76,9 @@ public function __construct($responseString, $status = null, $params = []) { */ public function getResponse() { if (null === $this->response) { - $this->response = json_decode($this->string, true); - /* $this->response = $this->bigIntToString ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) : json_decode($this->string, true); - */ if (json_last_error() !== JSON_ERROR_NONE) { if (json_last_error() !== JSON_ERROR_UTF8 || !$this->stripBadUtf8()) { throw new RuntimeException( From deb15459e1515077fb9059093afe2ade08741241 Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 14:31:06 +0700 Subject: [PATCH 05/14] Enhanced handling of json responses with 5xx statuses --- src/Manticoresearch/Client.php | 7 ++++-- src/Manticoresearch/Response.php | 43 +++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index 657c873..7c5327a 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -16,10 +16,12 @@ use Manticoresearch\Endpoints\Pq; use Manticoresearch\Exceptions\ConnectionException; use Manticoresearch\Exceptions\NoMoreNodesException; +use Manticoresearch\Exceptions\ResponseException; use Manticoresearch\Exceptions\RuntimeException; use Manticoresearch\Response\SqlToArray; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Manticoresearch\Exceptions\ResponseException; /** * Manticore client object @@ -422,16 +424,17 @@ public function request(Request $request, array $params = [], string $retryReaso $this->initConnections(); throw $e; - } catch (ConnectionException $e) { + } catch (ConnectionException | ResponseException $e) { if (!$this->connectionPool->retries) { throw new NoMoreNodesException($e); } + $failContext = ($e::class === ResponseException::class) ? 'bad response' : 'attempt'; $exMsg = $e->getMessage(); // We rely on the common error message format from Manticore here $exReasonPos = strrpos($exMsg, ':'); $exceptionReason = substr($exMsg, ($exReasonPos === false) ? 0 : $exReasonPos + 1); $this->logger->warning( - 'Manticore Search Request failed on attempt ' . $this->connectionPool->retriesAttempts . ':', + "Manticore Search Request failed on $failContext " . $this->connectionPool->retriesAttempts . ':', [ 'exception' => $exMsg, 'request' => $e->getRequest()->toArray(), diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index e192c85..2d67b81 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -16,6 +16,7 @@ * @link https://manticoresearch.com */ use Manticoresearch\Exceptions\RuntimeException; +use Manticoresearch\Exceptions\ResponseException; /** * Class Response @@ -75,24 +76,35 @@ public function __construct($responseString, $status = null, $params = []) { * @return array */ public function getResponse() { - if (null === $this->response) { - $this->response = $this->bigIntToString - ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) - : json_decode($this->string, true); - if (json_last_error() !== JSON_ERROR_NONE) { - if (json_last_error() !== JSON_ERROR_UTF8 || !$this->stripBadUtf8()) { - throw new RuntimeException( - 'fatal error while trying to decode JSON response: ' . json_last_error_msg() - ); - } - - $this->response = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $this->string), true); + if (null !== $this->response) { + return $this->response; + } + + $this->response = $this->bigIntToString + ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) + : json_decode($this->string, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + // If server returns 5xx error, we suppose it to be temporary and attempt retries + if ($this->status >= 500 && $this->status < 600) { + throw new ResponseException( + new Request($this->getTransportInfo()), + $this + ); } - - if (empty($this->response)) { - $this->response = []; + if (json_last_error() !== JSON_ERROR_UTF8 || !$this->stripBadUtf8()) { + throw new RuntimeException( + 'fatal error while trying to decode JSON response: ' . json_last_error_msg() + ); } + + $this->response = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $this->string), true); + } + + if (empty($this->response)) { + $this->response = []; } + return $this->response; } @@ -126,6 +138,7 @@ public function hasError() { * @return false|string */ public function getError() { + // check if this->error $response = $this->getResponse(); if (isset($response['error'])) { return json_encode($response['error'], true); From 365bb7bcb33b6239e90fbeab49c16e6d691ef7bd Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 14:54:45 +0700 Subject: [PATCH 06/14] updated handling logic; added appropriate test --- src/Manticoresearch/Client.php | 8 ++++++-- .../Exceptions/ResponseException.php | 8 ++++++++ src/Manticoresearch/Response.php | 13 +++++++++++-- test/Manticoresearch/ResponseTest.php | 10 ++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index 7c5327a..1d8cdde 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -21,7 +21,6 @@ use Manticoresearch\Response\SqlToArray; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Manticoresearch\Exceptions\ResponseException; /** * Manticore client object @@ -428,7 +427,12 @@ public function request(Request $request, array $params = [], string $retryReaso if (!$this->connectionPool->retries) { throw new NoMoreNodesException($e); } - $failContext = ($e::class === ResponseException::class) ? 'bad response' : 'attempt'; + if ($e::class === ResponseException::class) { + $e->setRequest($request); + $failContext = 'bad response'; + } else { + $failContext = 'attempt'; + } $exMsg = $e->getMessage(); // We rely on the common error message format from Manticore here $exReasonPos = strrpos($exMsg, ':'); diff --git a/src/Manticoresearch/Exceptions/ResponseException.php b/src/Manticoresearch/Exceptions/ResponseException.php index 94848d2..860566a 100644 --- a/src/Manticoresearch/Exceptions/ResponseException.php +++ b/src/Manticoresearch/Exceptions/ResponseException.php @@ -44,6 +44,14 @@ public function getRequest() :Request { return $this->request; } + /** + * + * @param Request $request + */ + public function setRequest(Request $request): void { + $this->request = $request; + } + /** * @return Response */ diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index 2d67b81..4f0afd8 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -61,6 +61,12 @@ class Response */ protected $bigIntToString = false; + /** + * Response error message + * @var string + */ + protected $error = ''; + public function __construct($responseString, $status = null, $params = []) { if (is_array($responseString)) { $this->response = $responseString; @@ -87,8 +93,9 @@ public function getResponse() { if (json_last_error() !== JSON_ERROR_NONE) { // If server returns 5xx error, we suppose it to be temporary and attempt retries if ($this->status >= 500 && $this->status < 600) { + $this->error = json_last_error_msg(); throw new ResponseException( - new Request($this->getTransportInfo()), + new Request(), $this ); } @@ -138,7 +145,9 @@ public function hasError() { * @return false|string */ public function getError() { - // check if this->error + if ($this->error) { + return $this->error; + } $response = $this->getResponse(); if (isset($response['error'])) { return json_encode($response['error'], true); diff --git a/test/Manticoresearch/ResponseTest.php b/test/Manticoresearch/ResponseTest.php index e26aad1..9607e1f 100644 --- a/test/Manticoresearch/ResponseTest.php +++ b/test/Manticoresearch/ResponseTest.php @@ -7,6 +7,7 @@ namespace Manticoresearch\Test; +use Manticoresearch\Exceptions\ResponseException; use Manticoresearch\Exceptions\RuntimeException; use Manticoresearch\Response; use PHPUnit\Framework\TestCase; @@ -40,4 +41,13 @@ public function testConstructorWithInvalidJSON() { $this->expectException(RuntimeException::class); $response->getResponse(); } + + public function test5xxInvalidJsonResponseException() { + $payload = '{invalid: json]'; + $response = new Response($payload, 500); + + $this->expectException(ResponseException::class); + $this->expectExceptionMessage('Syntax error'); + $response->getResponse(); + } } From b2b1916360947ea13cce875a0ff280cf1f2219cb Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 14:58:51 +0700 Subject: [PATCH 07/14] Fixed codestyle and phpstan errors --- src/Manticoresearch/Connection.php | 22 +++++++++++++++++----- src/Manticoresearch/Response.php | 6 +++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Manticoresearch/Connection.php b/src/Manticoresearch/Connection.php index b32b3a7..50745d9 100644 --- a/src/Manticoresearch/Connection.php +++ b/src/Manticoresearch/Connection.php @@ -26,7 +26,7 @@ class Connection protected $alive = true; /** - * @var resource + * @var \CurlHandle|null */ protected $curl = null; @@ -69,7 +69,11 @@ public function __construct(array $params) { if (!$this->config['persistent']) { return; } - $this->curl = curl_init(); + $curl = curl_init(); + if ($curl === false) { + throw new RuntimeException('Unable to initialize cURL'); + } + $this->curl = $curl; } /** @@ -246,11 +250,19 @@ public function mark(bool $state) { } /** - * @return resource|null - * + * @return \CurlHandle */ public function getCurl() { - return $this->curl ?? curl_init(); + if ($this->curl instanceof \CurlHandle) { + return $this->curl; + } + + $curl = curl_init(); + if ($curl === false) { + throw new RuntimeException('Unable to initialize cURL'); + } + + return $curl; } } diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index 4f0afd8..11dd1b1 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -15,8 +15,8 @@ * @author Adrian Nuta * @link https://manticoresearch.com */ -use Manticoresearch\Exceptions\RuntimeException; use Manticoresearch\Exceptions\ResponseException; +use Manticoresearch\Exceptions\RuntimeException; /** * Class Response @@ -85,7 +85,7 @@ public function getResponse() { if (null !== $this->response) { return $this->response; } - + $this->response = $this->bigIntToString ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) : json_decode($this->string, true); @@ -111,7 +111,7 @@ public function getResponse() { if (empty($this->response)) { $this->response = []; } - + return $this->response; } From fc32f7ce7b6ea026f1e60ee6b4aba0e6cc9ca68f Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 15:15:02 +0700 Subject: [PATCH 08/14] Fixed phpstan errors --- src/Manticoresearch/Client.php | 2 +- src/Manticoresearch/Connection.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index 1d8cdde..9b969db 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -427,7 +427,7 @@ public function request(Request $request, array $params = [], string $retryReaso if (!$this->connectionPool->retries) { throw new NoMoreNodesException($e); } - if ($e::class === ResponseException::class) { + if ($e instanceof ResponseException) { $e->setRequest($request); $failContext = 'bad response'; } else { diff --git a/src/Manticoresearch/Connection.php b/src/Manticoresearch/Connection.php index 50745d9..b2baa98 100644 --- a/src/Manticoresearch/Connection.php +++ b/src/Manticoresearch/Connection.php @@ -26,7 +26,7 @@ class Connection protected $alive = true; /** - * @var \CurlHandle|null + * @var resource|\CurlHandle|null */ protected $curl = null; @@ -250,10 +250,10 @@ public function mark(bool $state) { } /** - * @return \CurlHandle + * @return resource|\CurlHandle */ public function getCurl() { - if ($this->curl instanceof \CurlHandle) { + if (is_resource($this->curl) || $this->curl instanceof \CurlHandle) { return $this->curl; } From f5a1873f14b15849a9d5f73fd2a940f85a1e4383 Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 15:23:11 +0700 Subject: [PATCH 09/14] Added phpstan stub --- phpstan.neon | 2 ++ stubs/curl_handle_stub.php | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 stubs/curl_handle_stub.php diff --git a/phpstan.neon b/phpstan.neon index 7740754..5caf272 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,3 +2,5 @@ parameters: level: 3 paths: - src + bootstrapFiles: + - stubs/curl_handle_stub.php \ No newline at end of file diff --git a/stubs/curl_handle_stub.php b/stubs/curl_handle_stub.php new file mode 100644 index 0000000..97d3245 --- /dev/null +++ b/stubs/curl_handle_stub.php @@ -0,0 +1,6 @@ + Date: Thu, 5 Mar 2026 16:00:35 +0700 Subject: [PATCH 10/14] Updated related tests --- test/Manticoresearch/Endpoints/InsertTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Manticoresearch/Endpoints/InsertTest.php b/test/Manticoresearch/Endpoints/InsertTest.php index acc397e..11bc468 100644 --- a/test/Manticoresearch/Endpoints/InsertTest.php +++ b/test/Manticoresearch/Endpoints/InsertTest.php @@ -20,6 +20,7 @@ public function testGetMethod() { } public function testInsert() { + require_once __DIR__ . '/../Helper/PopulateHelperTest.php'; $helper = new \Manticoresearch\Test\Helper\PopulateHelperTest('testDummy'); $helper->populateForKeywords(); $client = $helper->getClient(); From 4482299f6e44b3a6580fd9819b1596e7924abfe3 Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 16:26:52 +0700 Subject: [PATCH 11/14] Fixed bug with handling not 5xx response exceptions --- src/Manticoresearch/Client.php | 5 +++++ src/Manticoresearch/Connection.php | 17 ++--------------- src/Manticoresearch/Response.php | 15 +++++++++++---- test/Manticoresearch/ResponseTest.php | 0 4 files changed, 18 insertions(+), 19 deletions(-) mode change 100644 => 100755 src/Manticoresearch/Connection.php mode change 100644 => 100755 test/Manticoresearch/ResponseTest.php diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index 9b969db..241a05a 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -427,7 +427,12 @@ public function request(Request $request, array $params = [], string $retryReaso if (!$this->connectionPool->retries) { throw new NoMoreNodesException($e); } + if ($e instanceof ResponseException) { + // We apply retrying to 5xx responses only + if (!$e->getResponse()->is5xxStatus()) { + throw $e; + } $e->setRequest($request); $failContext = 'bad response'; } else { diff --git a/src/Manticoresearch/Connection.php b/src/Manticoresearch/Connection.php old mode 100644 new mode 100755 index b2baa98..ff11725 --- a/src/Manticoresearch/Connection.php +++ b/src/Manticoresearch/Connection.php @@ -69,11 +69,7 @@ public function __construct(array $params) { if (!$this->config['persistent']) { return; } - $curl = curl_init(); - if ($curl === false) { - throw new RuntimeException('Unable to initialize cURL'); - } - $this->curl = $curl; + $this->curl = curl_init(); } /** @@ -253,16 +249,7 @@ public function mark(bool $state) { * @return resource|\CurlHandle */ public function getCurl() { - if (is_resource($this->curl) || $this->curl instanceof \CurlHandle) { - return $this->curl; - } - - $curl = curl_init(); - if ($curl === false) { - throw new RuntimeException('Unable to initialize cURL'); - } - - return $curl; + return $this->curl ?? curl_init(); } } diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index 11dd1b1..308ef3a 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -86,13 +86,13 @@ public function getResponse() { return $this->response; } - $this->response = $this->bigIntToString - ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) - : json_decode($this->string, true); + //$this->response = $this->bigIntToString + // ? json_decode($this->string, true, 512, JSON_BIGINT_AS_STRING) + $this->response = json_decode($this->string, true); if (json_last_error() !== JSON_ERROR_NONE) { // If server returns 5xx error, we suppose it to be temporary and attempt retries - if ($this->status >= 500 && $this->status < 600) { + if ($this->is5xxStatus()) { $this->error = json_last_error_msg(); throw new ResponseException( new Request(), @@ -190,6 +190,13 @@ public function getTime() { return $this->time; } + /* + * @return bool + */ + public function is5xxStatus() { + return $this->status >= 500 && $this->status < 600; + } + /** * set request info * @param array $info diff --git a/test/Manticoresearch/ResponseTest.php b/test/Manticoresearch/ResponseTest.php old mode 100644 new mode 100755 From 1bea6b046c42422e20f48fb75a135e21a07c24b3 Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 16:38:08 +0700 Subject: [PATCH 12/14] Updated 5xx status code interval to be handled; updated related test --- src/Manticoresearch/Client.php | 2 +- src/Manticoresearch/Response.php | 2 +- test/Manticoresearch/Endpoints/InsertTest.php | 1 - test/Manticoresearch/Endpoints/KeywordsTest.php | 1 - test/Manticoresearch/ResponseTest.php | 2 +- 5 files changed, 3 insertions(+), 5 deletions(-) mode change 100644 => 100755 test/Manticoresearch/Endpoints/InsertTest.php diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index 241a05a..0200d6c 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -429,7 +429,7 @@ public function request(Request $request, array $params = [], string $retryReaso } if ($e instanceof ResponseException) { - // We apply retrying to 5xx responses only + // We apply retrying to 502-600 responses only if (!$e->getResponse()->is5xxStatus()) { throw $e; } diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index 308ef3a..b6bc27a 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -194,7 +194,7 @@ public function getTime() { * @return bool */ public function is5xxStatus() { - return $this->status >= 500 && $this->status < 600; + return $this->status >= 502 && $this->status < 600; } /** diff --git a/test/Manticoresearch/Endpoints/InsertTest.php b/test/Manticoresearch/Endpoints/InsertTest.php old mode 100644 new mode 100755 index 11bc468..acc397e --- a/test/Manticoresearch/Endpoints/InsertTest.php +++ b/test/Manticoresearch/Endpoints/InsertTest.php @@ -20,7 +20,6 @@ public function testGetMethod() { } public function testInsert() { - require_once __DIR__ . '/../Helper/PopulateHelperTest.php'; $helper = new \Manticoresearch\Test\Helper\PopulateHelperTest('testDummy'); $helper->populateForKeywords(); $client = $helper->getClient(); diff --git a/test/Manticoresearch/Endpoints/KeywordsTest.php b/test/Manticoresearch/Endpoints/KeywordsTest.php index dfb5ce6..2281f4b 100644 --- a/test/Manticoresearch/Endpoints/KeywordsTest.php +++ b/test/Manticoresearch/Endpoints/KeywordsTest.php @@ -19,7 +19,6 @@ class KeywordsTest extends \PHPUnit\Framework\TestCase public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - $helper = new PopulateHelperTest('testDummy'); $helper->populateForKeywords(); static::$client = $helper->getClient(); diff --git a/test/Manticoresearch/ResponseTest.php b/test/Manticoresearch/ResponseTest.php index 9607e1f..0751cf6 100755 --- a/test/Manticoresearch/ResponseTest.php +++ b/test/Manticoresearch/ResponseTest.php @@ -44,7 +44,7 @@ public function testConstructorWithInvalidJSON() { public function test5xxInvalidJsonResponseException() { $payload = '{invalid: json]'; - $response = new Response($payload, 500); + $response = new Response($payload, 502); $this->expectException(ResponseException::class); $this->expectExceptionMessage('Syntax error'); From cfbca2abe86fc16cee522987a5bddf30a7ff4c9e Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 16:40:30 +0700 Subject: [PATCH 13/14] Updated 5xx status code interval to be handled; updated related test --- src/Manticoresearch/Response.php | 4 ++-- test/Manticoresearch/ResponseTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index b6bc27a..2030252 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -193,8 +193,8 @@ public function getTime() { /* * @return bool */ - public function is5xxStatus() { - return $this->status >= 502 && $this->status < 600; + public function is5xxRetriedStatus() { + return $this->status >= 503 && $this->status < 505; } /** diff --git a/test/Manticoresearch/ResponseTest.php b/test/Manticoresearch/ResponseTest.php index 0751cf6..75b6ecb 100755 --- a/test/Manticoresearch/ResponseTest.php +++ b/test/Manticoresearch/ResponseTest.php @@ -44,7 +44,7 @@ public function testConstructorWithInvalidJSON() { public function test5xxInvalidJsonResponseException() { $payload = '{invalid: json]'; - $response = new Response($payload, 502); + $response = new Response($payload, 503); $this->expectException(ResponseException::class); $this->expectExceptionMessage('Syntax error'); From ec303854c28b2ce96d2bed5798fc240aefb90b44 Mon Sep 17 00:00:00 2001 From: nick80 Date: Thu, 5 Mar 2026 16:42:07 +0700 Subject: [PATCH 14/14] Fixed typos --- src/Manticoresearch/Client.php | 2 +- src/Manticoresearch/Response.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index 0200d6c..782c112 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -430,7 +430,7 @@ public function request(Request $request, array $params = [], string $retryReaso if ($e instanceof ResponseException) { // We apply retrying to 502-600 responses only - if (!$e->getResponse()->is5xxStatus()) { + if (!$e->getResponse()->is5xxRetriedStatus()) { throw $e; } $e->setRequest($request); diff --git a/src/Manticoresearch/Response.php b/src/Manticoresearch/Response.php index 2030252..eef6780 100755 --- a/src/Manticoresearch/Response.php +++ b/src/Manticoresearch/Response.php @@ -92,7 +92,7 @@ public function getResponse() { if (json_last_error() !== JSON_ERROR_NONE) { // If server returns 5xx error, we suppose it to be temporary and attempt retries - if ($this->is5xxStatus()) { + if ($this->is5xxRetriedStatus()) { $this->error = json_last_error_msg(); throw new ResponseException( new Request(),