Skip to content

Commit 785608e

Browse files
authored
Merge pull request #44 from hollodotme/2.x-dev
Release v2.7.1
2 parents 8c39b84 + c02a533 commit 785608e

File tree

11 files changed

+621
-41
lines changed

11 files changed

+621
-41
lines changed

.docker/php/7.1/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM php:7.1-fpm-alpine
2+
ENV XDEBUG_VERSION=2.7.2
23
ENV PHP_CONF_DIR=/usr/local/etc
3-
RUN apk update && apk upgrade && apk add --no-cache $PHPIZE_DEPS \
4-
&& pecl install xdebug-2.7.1 \
4+
RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \
5+
&& pecl install xdebug-${XDEBUG_VERSION} \
56
&& docker-php-ext-enable xdebug \
6-
&& apk del $PHPIZE_DEPS
7-
COPY network-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/network-socket.pool.conf
8-
COPY restricted-unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/restricted-unix-domain-socket.pool.conf
9-
COPY unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/unix-domain-socket.pool.conf
7+
&& apk del ${PHPIZE_DEPS} \
8+
&& rm -rf /var/cache/apk/*
9+
COPY network-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/network-socket.pool.conf
10+
COPY restricted-unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/restricted-unix-domain-socket.pool.conf
11+
COPY unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/unix-domain-socket.pool.conf
1012
WORKDIR /repo

.docker/php/7.2/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM php:7.2-fpm-alpine
2+
ENV XDEBUG_VERSION=2.7.2
23
ENV PHP_CONF_DIR=/usr/local/etc
3-
RUN apk update && apk upgrade && apk add --no-cache $PHPIZE_DEPS \
4-
&& pecl install xdebug-2.7.1 \
4+
RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \
5+
&& pecl install xdebug-${XDEBUG_VERSION} \
56
&& docker-php-ext-enable xdebug \
6-
&& apk del $PHPIZE_DEPS
7-
COPY network-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/network-socket.pool.conf
8-
COPY restricted-unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/restricted-unix-domain-socket.pool.conf
9-
COPY unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/unix-domain-socket.pool.conf
7+
&& apk del ${PHPIZE_DEPS} \
8+
&& rm -rf /var/cache/apk/*
9+
COPY network-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/network-socket.pool.conf
10+
COPY restricted-unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/restricted-unix-domain-socket.pool.conf
11+
COPY unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/unix-domain-socket.pool.conf
1012
WORKDIR /repo

.docker/php/7.3/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM php:7.3-fpm-alpine
2+
ENV XDEBUG_VERSION=2.7.2
23
ENV PHP_CONF_DIR=/usr/local/etc
3-
RUN apk update && apk upgrade && apk add --no-cache $PHPIZE_DEPS \
4-
&& pecl install xdebug-2.7.1 \
4+
RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \
5+
&& pecl install xdebug-${XDEBUG_VERSION} \
56
&& docker-php-ext-enable xdebug \
6-
&& apk del $PHPIZE_DEPS
7-
COPY network-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/network-socket.pool.conf
8-
COPY restricted-unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/restricted-unix-domain-socket.pool.conf
9-
COPY unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/unix-domain-socket.pool.conf
7+
&& apk del ${PHPIZE_DEPS} \
8+
&& rm -rf /var/cache/apk/*
9+
COPY network-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/network-socket.pool.conf
10+
COPY restricted-unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/restricted-unix-domain-socket.pool.conf
11+
COPY unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/unix-domain-socket.pool.conf
1012
WORKDIR /repo

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/.idea/
22
/vendor/
33
/build/logs/
4-
/.phpunit.result.cache
4+
/build/.phpunit.result.cache
55
/composer.lock

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com).
55

6+
## [2.7.2] - 2019-05-31
7+
8+
### Improved
9+
10+
* Handling of `stream_select` returning `false` in case of a system call interrupt. - [#41]
11+
12+
### Fixed
13+
14+
* Remove/close sockets after fetching their responses triggered async requests in order to prevent halt on further
15+
request processing, if the number of requests exceeds php-fpm's `pm.max_children` setting. - [#40]
16+
617
## [2.7.1] - 2019-04-29
718

819
### Fixed
@@ -193,6 +204,7 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http
193204
* Getters/Setters for connect timeout, read/write timeout, keep alive, socket persistence from `Client` (now part of the socket connection)
194205
* Method `Client->getValues()`
195206

207+
[2.7.2]: https://github.com/hollodotme/fast-cgi-client/compare/v2.7.1...v2.7.2
196208
[2.7.1]: https://github.com/hollodotme/fast-cgi-client/compare/v2.7.0...v2.7.1
197209
[2.7.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.6.0...v2.7.0
198210
[2.6.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.5.0...v2.6.0
@@ -221,3 +233,5 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http
221233
[#27]: https://github.com/hollodotme/fast-cgi-client/issues/27
222234
[#33]: https://github.com/hollodotme/fast-cgi-client/pull/33
223235
[#37]: https://github.com/hollodotme/fast-cgi-client/issue/37
236+
[#40]: https://github.com/hollodotme/fast-cgi-client/issue/40
237+
[#41]: https://github.com/hollodotme/fast-cgi-client/issue/41

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"keywords": [
55
"fastcgi",
66
"php-fpm",
7-
"socket"
7+
"socket",
8+
"async"
89
],
910
"minimum-stability": "dev",
1011
"prefer-stable": true,

src/Client.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,7 @@ public function waitForResponses( ?int $timeoutMs = null ) : void
172172

173173
while ( $this->hasUnhandledResponses() )
174174
{
175-
foreach ( $this->getSocketsHavingResponse() as $socket )
176-
{
177-
$this->fetchResponseAndNotifyCallback( $socket, $timeoutMs );
178-
}
175+
$this->handleReadyResponses( $timeoutMs );
179176
}
180177
}
181178

@@ -193,10 +190,12 @@ private function fetchResponseAndNotifyCallback( Socket $socket, ?int $timeoutMs
193190
}
194191
catch ( Throwable $e )
195192
{
196-
$this->sockets->remove( $socket->getId() );
197-
198193
$socket->notifyFailureCallbacks( $e );
199194
}
195+
finally
196+
{
197+
$this->sockets->remove( $socket->getId() );
198+
}
200199
}
201200

202201
/**
@@ -207,18 +206,6 @@ public function hasUnhandledResponses() : bool
207206
return $this->sockets->hasBusySockets();
208207
}
209208

210-
/**
211-
* @return Generator|Socket[]
212-
* @throws ReadFailedException
213-
*/
214-
private function getSocketsHavingResponse() : Generator
215-
{
216-
foreach ( $this->getRequestIdsHavingResponse() as $requestId )
217-
{
218-
yield $this->sockets->getById( $requestId );
219-
}
220-
}
221-
222209
/**
223210
* @param int $requestId
224211
*
@@ -244,7 +231,12 @@ public function getRequestIdsHavingResponse() : array
244231
$reads = $this->sockets->collectResources();
245232
$writes = $excepts = null;
246233

247-
stream_select( $reads, $writes, $excepts, 0, Socket::STREAM_SELECT_USEC );
234+
$result = @stream_select( $reads, $writes, $excepts, 0, Socket::STREAM_SELECT_USEC );
235+
236+
if ( false === $result || 0 === count( $reads ) )
237+
{
238+
return [];
239+
}
248240

249241
return $this->sockets->getSocketIdsByResources( $reads );
250242
}
@@ -264,6 +256,10 @@ public function readResponses( ?int $timeoutMs = null, int ...$requestIds ) : Ge
264256
yield $this->sockets->getById( $requestId )->fetchResponse( $timeoutMs );
265257
}
266258
catch ( Throwable $e )
259+
{
260+
# Skip unknown request ids
261+
}
262+
finally
267263
{
268264
$this->sockets->remove( $requestId );
269265
}

src/Sockets/Socket.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
use function stream_select;
5353
use function stream_set_timeout;
5454
use function stream_socket_client;
55+
use function stream_socket_shutdown;
5556
use function strlen;
5657
use function substr;
58+
use const STREAM_SHUT_RDWR;
5759

5860
final class Socket
5961
{
@@ -541,6 +543,7 @@ private function disconnect() : void
541543
{
542544
if ( is_resource( $this->resource ) )
543545
{
546+
@stream_socket_shutdown( $this->resource, STREAM_SHUT_RDWR );
544547
fclose( $this->resource );
545548
}
546549
}

0 commit comments

Comments
 (0)