From f6579304d7921aeac1010357efe9bf437bf0f265 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Sat, 18 Nov 2017 23:56:07 +0100 Subject: [PATCH] Fixes PHP warning when trying to get ready request IDs, #14 --- CHANGELOG.md | 6 ++++++ src/Client.php | 10 ++++++---- tests/Unit/ClientTest.php | 10 ++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ab9ee6..366c773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com). +## [1.4.1] - 2017-11-19 + +* Fixes PHP warning when trying to get ready request IDs - [#14] + ## [1.4.0] - 2017-09-28 ### Added @@ -104,6 +108,7 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http * Getters/Setters for connect timeout, read/write timeout, keep alive, socket persistence from `Client` (now part of the socket connection) * Method `Client->getValues()` +[1.4.1]: https://github.com/hollodotme/fast-cgi-client/compare/v1.4.0...v1.4.1 [1.4.0]: https://github.com/hollodotme/fast-cgi-client/compare/v1.3.0...v1.4.0 [1.3.0]: https://github.com/hollodotme/fast-cgi-client/compare/v1.2.0...v1.3.0 [1.2.0]: https://github.com/hollodotme/fast-cgi-client/compare/v1.1.0...v1.2.0 @@ -117,3 +122,4 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http [#6]: https://github.com/hollodotme/fast-cgi-client/issues/6 [#9]: https://github.com/hollodotme/fast-cgi-client/issues/9 [#11]: https://github.com/hollodotme/fast-cgi-client/issues/11 +[#14]: https://github.com/hollodotme/fast-cgi-client/issues/14 diff --git a/src/Client.php b/src/Client.php index 1cdd0df..4a86137 100644 --- a/src/Client.php +++ b/src/Client.php @@ -258,6 +258,11 @@ public function hasResponse( int $requestId ) : bool */ public function getRequestIdsHavingResponse() : array { + if ( \count( $this->sockets ) === 0 ) + { + return []; + } + $resources = []; $writes = $excepts = null; @@ -343,9 +348,6 @@ public function handleReadyResponses( $timeoutMs = null ) { $requestIds = $this->getRequestIdsHavingResponse(); - if ( \count( $requestIds ) > 0 ) - { - $this->handleResponses( $timeoutMs, ...$requestIds ); - } + $this->handleResponses( $timeoutMs, ...$requestIds ); } } diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index d34c7d5..26c18dd 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -118,4 +118,14 @@ public function testConnectAttemptToRestrictedUnixDomainSocketThrowsException() $client->sendRequest( new PostRequest( '/path/to/script.php', '' ) ); } + + public function testHandlingReadyResponsesJustReturnsIfClientGotNoRequests() + { + $connection = new UnixDomainSocket( '/var/run/php7.0-ruds.sock' ); + $client = new Client( $connection ); + + $this->assertFalse( $client->hasUnhandledResponses() ); + + $client->handleReadyResponses(); + } }