Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
hollodotme committed Nov 18, 2017
2 parents 83fd65c + ecb6dc3 commit 8f9db4f
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 63 deletions.
37 changes: 37 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
* @hollodotme

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
# *.js @js-owner

# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
# *.go [email protected]

# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
# /build/logs/ @doctocat

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
# docs/* [email protected]

# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
# apps/ @octocat

# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository.
# /docs/ @doctocat
15 changes: 12 additions & 3 deletions CONTRIBUTING.md → .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ We accept contributions via pull requests on [GitHub](https://github.com/hollodo

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.


## Running Tests
## Running tests

- Add the relevant pools to a working php-fpm service:
- [for PHP-FPM 7.0](./env/php-fpm/7.0)
- [for PHP-FPM 7.1](./env/php-fpm/7.1)

- Then run tests:

$ php vendor/bin/phpunit.phar -c build/
```bash
$ php vendor/bin/phpunit.phar -c build/
```

This includes a code coverage report in HTML and Clover XML.

## Analyze code

```bash
$ php vendor/bin/phpmetrics.phar --report-html=build/logs/phpmetrics src/
```
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Expected Behavior


## Actual Behavior


## Steps to Reproduce the Problem

1.
2.
3.

## Specifications

- Package version:
- PHP version:
- Platform/OS:
- Subsystem:

## Further comments
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Fixes #`<issue-number>`

## Proposed Changes

-
-
-

## Further comments
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
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.4.1] - 2017-11-19

### Fixes

* PHP warning when trying to get ready request IDs - [#14]

### Improves

* Loop performance

## [2.4.0] - 2017-09-28

### Added
Expand Down Expand Up @@ -114,6 +124,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.4.1]: https://github.com/hollodotme/fast-cgi-client/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.1.0...v2.2.0
Expand All @@ -128,3 +139,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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
"extra": {
"tools": {
"phpunit": {
"url": "https://phar.phpunit.de/phpunit-6.3.1.phar",
"url": "https://phar.phpunit.de/phpunit-6.4.4.phar",
"only-dev": true
},
"coveralls": {
"url": "https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar",
"only-dev": true
},
"phpmetrics": {
"url": "https://github.com/phpmetrics/PhpMetrics/releases/download/v2.3.0/phpmetrics.phar",
"url": "https://github.com/phpmetrics/PhpMetrics/releases/download/v2.3.2/phpmetrics.phar",
"only-dev": true
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
*/
class Client
{
private const LOOP_TICK_USEC = 2000;

/** @var ConfiguresSocketConnection */
private $connection;

Expand Down Expand Up @@ -160,8 +158,6 @@ public function waitForResponse( int $requestId, ?int $timeoutMs = null ) : void
$this->fetchResponseAndNotifyCallback( $socket, $timeoutMs );
break;
}

usleep( self::LOOP_TICK_USEC );
}
}

Expand All @@ -173,7 +169,7 @@ public function waitForResponse( int $requestId, ?int $timeoutMs = null ) : void
*/
public function waitForResponses( ?int $timeoutMs = null ) : void
{
if ( count( $this->sockets ) === 0 )
if ( \count( $this->sockets ) === 0 )
{
throw new ReadFailedException( 'No pending requests found.' );
}
Expand All @@ -184,8 +180,6 @@ public function waitForResponses( ?int $timeoutMs = null ) : void
{
$this->fetchResponseAndNotifyCallback( $socket, $timeoutMs );
}

usleep( self::LOOP_TICK_USEC );
}
}

Expand Down Expand Up @@ -216,7 +210,7 @@ private function fetchResponseAndNotifyCallback( Socket $socket, ?int $timeoutMs
*/
public function hasUnhandledResponses() : bool
{
return (count( $this->sockets ) > 0);
return (\count( $this->sockets ) > 0);
}

/**
Expand Down Expand Up @@ -258,6 +252,11 @@ public function hasResponse( int $requestId ) : bool
*/
public function getRequestIdsHavingResponse() : array
{
if ( \count( $this->sockets ) === 0 )
{
return [];
}

$resources = [];
$writes = $excepts = null;

Expand Down Expand Up @@ -307,7 +306,7 @@ public function readReadyResponses( ?int $timeoutMs = null ) : \Generator
{
$requestIds = $this->getRequestIdsHavingResponse();

if ( count( $requestIds ) > 0 )
if ( \count( $requestIds ) > 0 )
{
yield from $this->readResponses( $timeoutMs, ...$requestIds );
}
Expand Down Expand Up @@ -343,9 +342,6 @@ public function handleReadyResponses( ?int $timeoutMs = null ) : void
{
$requestIds = $this->getRequestIdsHavingResponse();

if ( count( $requestIds ) > 0 )
{
$this->handleResponses( $timeoutMs, ...$requestIds );
}
$this->handleResponses( $timeoutMs, ...$requestIds );
}
}
42 changes: 21 additions & 21 deletions src/Encoders/NameValuePairEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,34 @@ public function encodePairs( array $pairs ) : string

public function encodePair( string $name, string $value ) : string
{
$nameLength = strlen( $name );
$valueLength = strlen( $value );
$nameLength = \strlen( $name );
$valueLength = \strlen( $value );

if ( $nameLength < 128 )
{
/* nameLengthB0 */
$nameValuePair = chr( $nameLength );
$nameValuePair = \chr( $nameLength );
}
else
{
/* nameLengthB3 & nameLengthB2 & nameLengthB1 & nameLengthB0 */
$nameValuePair = chr( ($nameLength >> 24) | 0x80 )
. chr( ($nameLength >> 16) & 0xFF )
. chr( ($nameLength >> 8) & 0xFF )
. chr( $nameLength & 0xFF );
$nameValuePair = \chr( ($nameLength >> 24) | 0x80 )
. \chr( ($nameLength >> 16) & 0xFF )
. \chr( ($nameLength >> 8) & 0xFF )
. \chr( $nameLength & 0xFF );
}
if ( $valueLength < 128 )
{
/* valueLengthB0 */
$nameValuePair .= chr( $valueLength );
$nameValuePair .= \chr( $valueLength );
}
else
{
/* valueLengthB3 & valueLengthB2 & valueLengthB1 & valueLengthB0 */
$nameValuePair .= chr( ($valueLength >> 24) | 0x80 )
. chr( ($valueLength >> 16) & 0xFF )
. chr( ($valueLength >> 8) & 0xFF )
. chr( $valueLength & 0xFF );
$nameValuePair .= \chr( ($valueLength >> 24) | 0x80 )
. \chr( ($valueLength >> 16) & 0xFF )
. \chr( ($valueLength >> 8) & 0xFF )
. \chr( $valueLength & 0xFF );
}

return $nameValuePair . $name . $value;
Expand All @@ -84,29 +84,29 @@ public function decodePairs( string $data, int $length = -1 ) : array

if ( $length === -1 )
{
$length = strlen( $data );
$length = \strlen( $data );
}

$p = 0;

while ( $p !== $length )
{
$nameLength = ord( $data{$p++} );
$nameLength = \ord( $data{$p++} );
if ( $nameLength >= 128 )
{
$nameLength &= (0x7F << 24);
$nameLength |= (ord( $data{$p++} ) << 16);
$nameLength |= (ord( $data{$p++} ) << 8);
$nameLength |= ord( $data{$p++} );
$nameLength |= (\ord( $data{$p++} ) << 16);
$nameLength |= (\ord( $data{$p++} ) << 8);
$nameLength |= \ord( $data{$p++} );
}

$valueLength = ord( $data{$p++} );
$valueLength = \ord( $data{$p++} );
if ( $valueLength >= 128 )
{
$valueLength = ($nameLength & 0x7F << 24);
$valueLength |= (ord( $data{$p++} ) << 16);
$valueLength |= (ord( $data{$p++} ) << 8);
$valueLength |= ord( $data{$p++} );
$valueLength |= (\ord( $data{$p++} ) << 16);
$valueLength |= (\ord( $data{$p++} ) << 8);
$valueLength |= \ord( $data{$p++} );
}
$array[ substr( $data, $p, $nameLength ) ] = substr( $data, $p + $nameLength, $valueLength );
$p += ($nameLength + $valueLength);
Expand Down
32 changes: 16 additions & 16 deletions src/Encoders/PacketEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ final class PacketEncoder implements EncodesPacket

public function encodePacket( int $type, string $content, int $requestId ) : string
{
$contentLength = strlen( $content );
$contentLength = \strlen( $content );

return chr( self::VERSION ) /* version */
. chr( $type ) /* type */
. chr( ($requestId >> 8) & 0xFF ) /* requestIdB1 */
. chr( $requestId & 0xFF ) /* requestIdB0 */
. chr( ($contentLength >> 8) & 0xFF ) /* contentLengthB1 */
. chr( $contentLength & 0xFF ) /* contentLengthB0 */
. chr( 0 ) /* paddingLength */
. chr( 0 ) /* reserved */
. $content; /* content */
return \chr( self::VERSION ) /* version */
. \chr( $type ) /* type */
. \chr( ($requestId >> 8) & 0xFF ) /* requestIdB1 */
. \chr( $requestId & 0xFF ) /* requestIdB0 */
. \chr( ($contentLength >> 8) & 0xFF ) /* contentLengthB1 */
. \chr( $contentLength & 0xFF ) /* contentLengthB0 */
. \chr( 0 ) /* paddingLength */
. \chr( 0 ) /* reserved */
. $content; /* content */
}

public function decodeHeader( string $data ) : array
{
$header = [];
$header['version'] = ord( $data{0} );
$header['type'] = ord( $data{1} );
$header['requestId'] = (ord( $data{2} ) << 8) + ord( $data{3} );
$header['contentLength'] = (ord( $data{4} ) << 8) + ord( $data{5} );
$header['paddingLength'] = ord( $data{6} );
$header['reserved'] = ord( $data{7} );
$header['version'] = \ord( $data{0} );
$header['type'] = \ord( $data{1} );
$header['requestId'] = (\ord( $data{2} ) << 8) + \ord( $data{3} );
$header['contentLength'] = (\ord( $data{4} ) << 8) + \ord( $data{5} );
$header['paddingLength'] = \ord( $data{6} );
$header['reserved'] = \ord( $data{7} );

return $header;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getContent() : string
public function setContent( string $content ) : void
{
$this->content = $content;
$this->contentLength = strlen( $content );
$this->contentLength = \strlen( $content );
}

public function setCustomVar( string $key, $value ) : void
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function parseHeadersAndBody() : void
break;
}

$this->body = implode( PHP_EOL, array_slice( $lines, $offset + 2 ) );
$this->body = implode( PHP_EOL, \array_slice( $lines, $offset + 2 ) );
}

public function getRequestId() : int
Expand Down
Loading

0 comments on commit 8f9db4f

Please sign in to comment.