Skip to content

Commit

Permalink
Merge pull request #44 from hollodotme/2.x-dev
Browse files Browse the repository at this point in the history
Release v2.7.1
  • Loading branch information
hollodotme authored May 30, 2019
2 parents 8c39b84 + c02a533 commit 785608e
Show file tree
Hide file tree
Showing 11 changed files with 621 additions and 41 deletions.
14 changes: 8 additions & 6 deletions .docker/php/7.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM php:7.1-fpm-alpine
ENV XDEBUG_VERSION=2.7.2
ENV PHP_CONF_DIR=/usr/local/etc
RUN apk update && apk upgrade && apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.7.1 \
RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \
&& pecl install xdebug-${XDEBUG_VERSION} \
&& docker-php-ext-enable xdebug \
&& apk del $PHPIZE_DEPS
COPY network-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/network-socket.pool.conf
COPY restricted-unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/restricted-unix-domain-socket.pool.conf
COPY unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/unix-domain-socket.pool.conf
&& apk del ${PHPIZE_DEPS} \
&& rm -rf /var/cache/apk/*
COPY network-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/network-socket.pool.conf
COPY restricted-unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/restricted-unix-domain-socket.pool.conf
COPY unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/unix-domain-socket.pool.conf
WORKDIR /repo
14 changes: 8 additions & 6 deletions .docker/php/7.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM php:7.2-fpm-alpine
ENV XDEBUG_VERSION=2.7.2
ENV PHP_CONF_DIR=/usr/local/etc
RUN apk update && apk upgrade && apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.7.1 \
RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \
&& pecl install xdebug-${XDEBUG_VERSION} \
&& docker-php-ext-enable xdebug \
&& apk del $PHPIZE_DEPS
COPY network-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/network-socket.pool.conf
COPY restricted-unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/restricted-unix-domain-socket.pool.conf
COPY unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/unix-domain-socket.pool.conf
&& apk del ${PHPIZE_DEPS} \
&& rm -rf /var/cache/apk/*
COPY network-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/network-socket.pool.conf
COPY restricted-unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/restricted-unix-domain-socket.pool.conf
COPY unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/unix-domain-socket.pool.conf
WORKDIR /repo
14 changes: 8 additions & 6 deletions .docker/php/7.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM php:7.3-fpm-alpine
ENV XDEBUG_VERSION=2.7.2
ENV PHP_CONF_DIR=/usr/local/etc
RUN apk update && apk upgrade && apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.7.1 \
RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \
&& pecl install xdebug-${XDEBUG_VERSION} \
&& docker-php-ext-enable xdebug \
&& apk del $PHPIZE_DEPS
COPY network-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/network-socket.pool.conf
COPY restricted-unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/restricted-unix-domain-socket.pool.conf
COPY unix-domain-socket.pool.conf $PHP_CONF_DIR/php-fpm.d/unix-domain-socket.pool.conf
&& apk del ${PHPIZE_DEPS} \
&& rm -rf /var/cache/apk/*
COPY network-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/network-socket.pool.conf
COPY restricted-unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/restricted-unix-domain-socket.pool.conf
COPY unix-domain-socket.pool.conf ${PHP_CONF_DIR}/php-fpm.d/unix-domain-socket.pool.conf
WORKDIR /repo
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.idea/
/vendor/
/build/logs/
/.phpunit.result.cache
/build/.phpunit.result.cache
/composer.lock
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
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).

## [2.7.2] - 2019-05-31

### Improved

* Handling of `stream_select` returning `false` in case of a system call interrupt. - [#41]

### Fixed

* Remove/close sockets after fetching their responses triggered async requests in order to prevent halt on further
request processing, if the number of requests exceeds php-fpm's `pm.max_children` setting. - [#40]

## [2.7.1] - 2019-04-29

### Fixed
Expand Down Expand Up @@ -193,6 +204,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()`

[2.7.2]: https://github.com/hollodotme/fast-cgi-client/compare/v2.7.1...v2.7.2
[2.7.1]: https://github.com/hollodotme/fast-cgi-client/compare/v2.7.0...v2.7.1
[2.7.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.6.0...v2.7.0
[2.6.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.5.0...v2.6.0
Expand Down Expand Up @@ -221,3 +233,5 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http
[#27]: https://github.com/hollodotme/fast-cgi-client/issues/27
[#33]: https://github.com/hollodotme/fast-cgi-client/pull/33
[#37]: https://github.com/hollodotme/fast-cgi-client/issue/37
[#40]: https://github.com/hollodotme/fast-cgi-client/issue/40
[#41]: https://github.com/hollodotme/fast-cgi-client/issue/41
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"keywords": [
"fastcgi",
"php-fpm",
"socket"
"socket",
"async"
],
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
34 changes: 15 additions & 19 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ public function waitForResponses( ?int $timeoutMs = null ) : void

while ( $this->hasUnhandledResponses() )
{
foreach ( $this->getSocketsHavingResponse() as $socket )
{
$this->fetchResponseAndNotifyCallback( $socket, $timeoutMs );
}
$this->handleReadyResponses( $timeoutMs );
}
}

Expand All @@ -193,10 +190,12 @@ private function fetchResponseAndNotifyCallback( Socket $socket, ?int $timeoutMs
}
catch ( Throwable $e )
{
$this->sockets->remove( $socket->getId() );

$socket->notifyFailureCallbacks( $e );
}
finally
{
$this->sockets->remove( $socket->getId() );
}
}

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

/**
* @return Generator|Socket[]
* @throws ReadFailedException
*/
private function getSocketsHavingResponse() : Generator
{
foreach ( $this->getRequestIdsHavingResponse() as $requestId )
{
yield $this->sockets->getById( $requestId );
}
}

/**
* @param int $requestId
*
Expand All @@ -244,7 +231,12 @@ public function getRequestIdsHavingResponse() : array
$reads = $this->sockets->collectResources();
$writes = $excepts = null;

stream_select( $reads, $writes, $excepts, 0, Socket::STREAM_SELECT_USEC );
$result = @stream_select( $reads, $writes, $excepts, 0, Socket::STREAM_SELECT_USEC );

if ( false === $result || 0 === count( $reads ) )
{
return [];
}

return $this->sockets->getSocketIdsByResources( $reads );
}
Expand All @@ -264,6 +256,10 @@ public function readResponses( ?int $timeoutMs = null, int ...$requestIds ) : Ge
yield $this->sockets->getById( $requestId )->fetchResponse( $timeoutMs );
}
catch ( Throwable $e )
{
# Skip unknown request ids
}
finally
{
$this->sockets->remove( $requestId );
}
Expand Down
3 changes: 3 additions & 0 deletions src/Sockets/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
use function stream_select;
use function stream_set_timeout;
use function stream_socket_client;
use function stream_socket_shutdown;
use function strlen;
use function substr;
use const STREAM_SHUT_RDWR;

final class Socket
{
Expand Down Expand Up @@ -541,6 +543,7 @@ private function disconnect() : void
{
if ( is_resource( $this->resource ) )
{
@stream_socket_shutdown( $this->resource, STREAM_SHUT_RDWR );
fclose( $this->resource );
}
}
Expand Down
Loading

0 comments on commit 785608e

Please sign in to comment.