Skip to content

Commit

Permalink
Fixes erroneous response returned by sendRequest and waitForResponse …
Browse files Browse the repository at this point in the history
…methods, see #1
  • Loading branch information
hollodotme committed Feb 23, 2017
1 parent 24accf4 commit f39d989
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
11 changes: 11 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).

## [1.0.1] - 2017-02-23

### Fixed

* Erroneous response returned by `Client::sendRequest()` and `Client::waitForResponse()` - [#1](https://github.com/hollodotme/fast-cgi-client/issues/1)

### Changed

* Testsuite updated for PHPUnit >= 6

## [1.0.0] - 2017-01-03

Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](https://github.com/adoy/PHP-FastCGI-Client/):
Expand All @@ -27,4 +37,5 @@ 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.0.1]: https://github.com/hollodotme/fast-cgi-client/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/hollodotme/fast-cgi-client/tree/v1.0.0
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,47 @@ $response = $client->waitForResponse(
);
```

### Responses

Assuming `/path/to/target/script.php` has the following content:

```php
<?php declare(strict_types=1);

echo "Hello World";
```

The response would look like this:

```
Content-type: text/html; charset=UTF-8
Hello World
```

**Please note:**
* All headers sent by your script will precede the response body
* There won't be any HTTP specific headers like `HTTP/1.1 200 OK`, because there is no webserver involved.

Custom headers will also be part of the response:

```php
<?php declare(strict_types=1);

header('X-Custom: Header');

echo "Hello World";
```

The response would look like this:

```
X-Custom: Header
Content-type: text/html; charset=UTF-8
Hello World
```

---

## Command line tool (for debugging only)
Expand Down
15 changes: 9 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private function readPacket()

if ( $response['paddingLength'] )
{
$response['content'] = fread( $this->socket, $response['paddingLength'] );
fread( $this->socket, $response['paddingLength'] );
}

return $response;
Expand Down Expand Up @@ -211,11 +211,13 @@ public function sendRequest( array $params, string $content ) : string
* In that case it is possible that a delayed response to a request made by a previous script
* invocation comes back on this socket and is mistaken for response to request made with same ID
* during this request.
*
* @param array $params Array of parameters
*
* @param array $params Array of parameters
* @param string $content Content
*
*@throws TimedoutException
*
* @throws TimedoutException
* @throws WriteFailedException
* @return int
*/
Expand Down Expand Up @@ -347,7 +349,8 @@ public function waitForResponse( int $requestId, int $timeoutMs = 0 ) : string

throw new TimedoutException( 'Timed out' );
}
} while ( $packet );
}
while ( null !== $packet );

if ( $packet === null )
{
Expand Down

0 comments on commit f39d989

Please sign in to comment.