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, closes #1
  • Loading branch information
hollodotme committed Feb 23, 2017
1 parent 17ac4d3 commit 594e8e2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 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).

## [2.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

## [2.0.0] - 2017-01-03

### Changed
Expand Down Expand Up @@ -37,5 +47,6 @@ 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.0.1]: https://github.com/hollodotme/fast-cgi-client/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/hollodotme/fast-cgi-client/compare/v1.0.0...v2.0.0
[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
5 changes: 3 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private function readPacket() : ?array

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

return $response;
Expand Down Expand Up @@ -349,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 594e8e2

Please sign in to comment.