Skip to content

Commit 8f9db4f

Browse files
committed
Merge branch 'development'
2 parents 83fd65c + ecb6dc3 commit 8f9db4f

14 files changed

+156
-63
lines changed

.github/CODEOWNERS

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence,
6+
# @global-owner1 and @global-owner2 will be requested for
7+
# review when someone opens a pull request.
8+
* @hollodotme
9+
10+
# Order is important; the last matching pattern takes the most
11+
# precedence. When someone opens a pull request that only
12+
# modifies JS files, only @js-owner and not the global
13+
# owner(s) will be requested for a review.
14+
# *.js @js-owner
15+
16+
# You can also use email addresses if you prefer. They'll be
17+
# used to look up users just like we do for commit author
18+
# emails.
19+
20+
21+
# In this example, @doctocat owns any files in the build/logs
22+
# directory at the root of the repository and any of its
23+
# subdirectories.
24+
# /build/logs/ @doctocat
25+
26+
# The `docs/*` pattern will match files like
27+
# `docs/getting-started.md` but not further nested files like
28+
# `docs/build-app/troubleshooting.md`.
29+
30+
31+
# In this example, @octocat owns any file in an apps directory
32+
# anywhere in your repository.
33+
# apps/ @octocat
34+
35+
# In this example, @doctocat owns any file in the `/docs`
36+
# directory in the root of your repository.
37+
# /docs/ @doctocat

CONTRIBUTING.md renamed to .github/CONTRIBUTING.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ We accept contributions via pull requests on [GitHub](https://github.com/hollodo
1818

1919
- **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.
2020

21-
22-
## Running Tests
21+
## Running tests
2322

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

2827
- Then run tests:
2928

30-
$ php vendor/bin/phpunit.phar -c build/
29+
```bash
30+
$ php vendor/bin/phpunit.phar -c build/
31+
```
32+
33+
This includes a code coverage report in HTML and Clover XML.
34+
35+
## Analyze code
36+
37+
```bash
38+
$ php vendor/bin/phpmetrics.phar --report-html=build/logs/phpmetrics src/
39+
```

.github/ISSUE_TEMPLATE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Expected Behavior
2+
3+
4+
## Actual Behavior
5+
6+
7+
## Steps to Reproduce the Problem
8+
9+
1.
10+
2.
11+
3.
12+
13+
## Specifications
14+
15+
- Package version:
16+
- PHP version:
17+
- Platform/OS:
18+
- Subsystem:
19+
20+
## Further comments

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Fixes #`<issue-number>`
2+
3+
## Proposed Changes
4+
5+
-
6+
-
7+
-
8+
9+
## Further comments

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
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.4.1] - 2017-11-19
7+
8+
### Fixes
9+
10+
* PHP warning when trying to get ready request IDs - [#14]
11+
12+
### Improves
13+
14+
* Loop performance
15+
616
## [2.4.0] - 2017-09-28
717

818
### Added
@@ -114,6 +124,7 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http
114124
* Getters/Setters for connect timeout, read/write timeout, keep alive, socket persistence from `Client` (now part of the socket connection)
115125
* Method `Client->getValues()`
116126

127+
[2.4.1]: https://github.com/hollodotme/fast-cgi-client/compare/v2.4.0...v2.4.1
117128
[2.4.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.3.0...v2.4.0
118129
[2.3.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.2.0...v2.3.0
119130
[2.2.0]: https://github.com/hollodotme/fast-cgi-client/compare/v2.1.0...v2.2.0
@@ -128,3 +139,4 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http
128139
[#6]: https://github.com/hollodotme/fast-cgi-client/issues/6
129140
[#9]: https://github.com/hollodotme/fast-cgi-client/issues/9
130141
[#11]: https://github.com/hollodotme/fast-cgi-client/issues/11
142+
[#14]: https://github.com/hollodotme/fast-cgi-client/issues/14

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
"extra": {
4242
"tools": {
4343
"phpunit": {
44-
"url": "https://phar.phpunit.de/phpunit-6.3.1.phar",
44+
"url": "https://phar.phpunit.de/phpunit-6.4.4.phar",
4545
"only-dev": true
4646
},
4747
"coveralls": {
4848
"url": "https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar",
4949
"only-dev": true
5050
},
5151
"phpmetrics": {
52-
"url": "https://github.com/phpmetrics/PhpMetrics/releases/download/v2.3.0/phpmetrics.phar",
52+
"url": "https://github.com/phpmetrics/PhpMetrics/releases/download/v2.3.2/phpmetrics.phar",
5353
"only-dev": true
5454
}
5555
}

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Client.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
*/
4040
class Client
4141
{
42-
private const LOOP_TICK_USEC = 2000;
43-
4442
/** @var ConfiguresSocketConnection */
4543
private $connection;
4644

@@ -160,8 +158,6 @@ public function waitForResponse( int $requestId, ?int $timeoutMs = null ) : void
160158
$this->fetchResponseAndNotifyCallback( $socket, $timeoutMs );
161159
break;
162160
}
163-
164-
usleep( self::LOOP_TICK_USEC );
165161
}
166162
}
167163

@@ -173,7 +169,7 @@ public function waitForResponse( int $requestId, ?int $timeoutMs = null ) : void
173169
*/
174170
public function waitForResponses( ?int $timeoutMs = null ) : void
175171
{
176-
if ( count( $this->sockets ) === 0 )
172+
if ( \count( $this->sockets ) === 0 )
177173
{
178174
throw new ReadFailedException( 'No pending requests found.' );
179175
}
@@ -184,8 +180,6 @@ public function waitForResponses( ?int $timeoutMs = null ) : void
184180
{
185181
$this->fetchResponseAndNotifyCallback( $socket, $timeoutMs );
186182
}
187-
188-
usleep( self::LOOP_TICK_USEC );
189183
}
190184
}
191185

@@ -216,7 +210,7 @@ private function fetchResponseAndNotifyCallback( Socket $socket, ?int $timeoutMs
216210
*/
217211
public function hasUnhandledResponses() : bool
218212
{
219-
return (count( $this->sockets ) > 0);
213+
return (\count( $this->sockets ) > 0);
220214
}
221215

222216
/**
@@ -258,6 +252,11 @@ public function hasResponse( int $requestId ) : bool
258252
*/
259253
public function getRequestIdsHavingResponse() : array
260254
{
255+
if ( \count( $this->sockets ) === 0 )
256+
{
257+
return [];
258+
}
259+
261260
$resources = [];
262261
$writes = $excepts = null;
263262

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

310-
if ( count( $requestIds ) > 0 )
309+
if ( \count( $requestIds ) > 0 )
311310
{
312311
yield from $this->readResponses( $timeoutMs, ...$requestIds );
313312
}
@@ -343,9 +342,6 @@ public function handleReadyResponses( ?int $timeoutMs = null ) : void
343342
{
344343
$requestIds = $this->getRequestIdsHavingResponse();
345344

346-
if ( count( $requestIds ) > 0 )
347-
{
348-
$this->handleResponses( $timeoutMs, ...$requestIds );
349-
}
345+
$this->handleResponses( $timeoutMs, ...$requestIds );
350346
}
351347
}

src/Encoders/NameValuePairEncoder.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,34 @@ public function encodePairs( array $pairs ) : string
4545

4646
public function encodePair( string $name, string $value ) : string
4747
{
48-
$nameLength = strlen( $name );
49-
$valueLength = strlen( $value );
48+
$nameLength = \strlen( $name );
49+
$valueLength = \strlen( $value );
5050

5151
if ( $nameLength < 128 )
5252
{
5353
/* nameLengthB0 */
54-
$nameValuePair = chr( $nameLength );
54+
$nameValuePair = \chr( $nameLength );
5555
}
5656
else
5757
{
5858
/* nameLengthB3 & nameLengthB2 & nameLengthB1 & nameLengthB0 */
59-
$nameValuePair = chr( ($nameLength >> 24) | 0x80 )
60-
. chr( ($nameLength >> 16) & 0xFF )
61-
. chr( ($nameLength >> 8) & 0xFF )
62-
. chr( $nameLength & 0xFF );
59+
$nameValuePair = \chr( ($nameLength >> 24) | 0x80 )
60+
. \chr( ($nameLength >> 16) & 0xFF )
61+
. \chr( ($nameLength >> 8) & 0xFF )
62+
. \chr( $nameLength & 0xFF );
6363
}
6464
if ( $valueLength < 128 )
6565
{
6666
/* valueLengthB0 */
67-
$nameValuePair .= chr( $valueLength );
67+
$nameValuePair .= \chr( $valueLength );
6868
}
6969
else
7070
{
7171
/* valueLengthB3 & valueLengthB2 & valueLengthB1 & valueLengthB0 */
72-
$nameValuePair .= chr( ($valueLength >> 24) | 0x80 )
73-
. chr( ($valueLength >> 16) & 0xFF )
74-
. chr( ($valueLength >> 8) & 0xFF )
75-
. chr( $valueLength & 0xFF );
72+
$nameValuePair .= \chr( ($valueLength >> 24) | 0x80 )
73+
. \chr( ($valueLength >> 16) & 0xFF )
74+
. \chr( ($valueLength >> 8) & 0xFF )
75+
. \chr( $valueLength & 0xFF );
7676
}
7777

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

8585
if ( $length === -1 )
8686
{
87-
$length = strlen( $data );
87+
$length = \strlen( $data );
8888
}
8989

9090
$p = 0;
9191

9292
while ( $p !== $length )
9393
{
94-
$nameLength = ord( $data{$p++} );
94+
$nameLength = \ord( $data{$p++} );
9595
if ( $nameLength >= 128 )
9696
{
9797
$nameLength &= (0x7F << 24);
98-
$nameLength |= (ord( $data{$p++} ) << 16);
99-
$nameLength |= (ord( $data{$p++} ) << 8);
100-
$nameLength |= ord( $data{$p++} );
98+
$nameLength |= (\ord( $data{$p++} ) << 16);
99+
$nameLength |= (\ord( $data{$p++} ) << 8);
100+
$nameLength |= \ord( $data{$p++} );
101101
}
102102

103-
$valueLength = ord( $data{$p++} );
103+
$valueLength = \ord( $data{$p++} );
104104
if ( $valueLength >= 128 )
105105
{
106106
$valueLength = ($nameLength & 0x7F << 24);
107-
$valueLength |= (ord( $data{$p++} ) << 16);
108-
$valueLength |= (ord( $data{$p++} ) << 8);
109-
$valueLength |= ord( $data{$p++} );
107+
$valueLength |= (\ord( $data{$p++} ) << 16);
108+
$valueLength |= (\ord( $data{$p++} ) << 8);
109+
$valueLength |= \ord( $data{$p++} );
110110
}
111111
$array[ substr( $data, $p, $nameLength ) ] = substr( $data, $p + $nameLength, $valueLength );
112112
$p += ($nameLength + $valueLength);

src/Encoders/PacketEncoder.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ final class PacketEncoder implements EncodesPacket
3535

3636
public function encodePacket( int $type, string $content, int $requestId ) : string
3737
{
38-
$contentLength = strlen( $content );
38+
$contentLength = \strlen( $content );
3939

40-
return chr( self::VERSION ) /* version */
41-
. chr( $type ) /* type */
42-
. chr( ($requestId >> 8) & 0xFF ) /* requestIdB1 */
43-
. chr( $requestId & 0xFF ) /* requestIdB0 */
44-
. chr( ($contentLength >> 8) & 0xFF ) /* contentLengthB1 */
45-
. chr( $contentLength & 0xFF ) /* contentLengthB0 */
46-
. chr( 0 ) /* paddingLength */
47-
. chr( 0 ) /* reserved */
48-
. $content; /* content */
40+
return \chr( self::VERSION ) /* version */
41+
. \chr( $type ) /* type */
42+
. \chr( ($requestId >> 8) & 0xFF ) /* requestIdB1 */
43+
. \chr( $requestId & 0xFF ) /* requestIdB0 */
44+
. \chr( ($contentLength >> 8) & 0xFF ) /* contentLengthB1 */
45+
. \chr( $contentLength & 0xFF ) /* contentLengthB0 */
46+
. \chr( 0 ) /* paddingLength */
47+
. \chr( 0 ) /* reserved */
48+
. $content; /* content */
4949
}
5050

5151
public function decodeHeader( string $data ) : array
5252
{
5353
$header = [];
54-
$header['version'] = ord( $data{0} );
55-
$header['type'] = ord( $data{1} );
56-
$header['requestId'] = (ord( $data{2} ) << 8) + ord( $data{3} );
57-
$header['contentLength'] = (ord( $data{4} ) << 8) + ord( $data{5} );
58-
$header['paddingLength'] = ord( $data{6} );
59-
$header['reserved'] = ord( $data{7} );
54+
$header['version'] = \ord( $data{0} );
55+
$header['type'] = \ord( $data{1} );
56+
$header['requestId'] = (\ord( $data{2} ) << 8) + \ord( $data{3} );
57+
$header['contentLength'] = (\ord( $data{4} ) << 8) + \ord( $data{5} );
58+
$header['paddingLength'] = \ord( $data{6} );
59+
$header['reserved'] = \ord( $data{7} );
6060

6161
return $header;
6262
}

src/Requests/AbstractRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function getContent() : string
177177
public function setContent( string $content ) : void
178178
{
179179
$this->content = $content;
180-
$this->contentLength = strlen( $content );
180+
$this->contentLength = \strlen( $content );
181181
}
182182

183183
public function setCustomVar( string $key, $value ) : void

src/Responses/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private function parseHeadersAndBody() : void
7676
break;
7777
}
7878

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

8282
public function getRequestId() : int

0 commit comments

Comments
 (0)