Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/09-stream-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
$server = new StreamingServer(function (ServerRequestInterface $request) {
return new Promise(function ($resolve, $reject) use ($request) {
$contentLength = 0;
$request->getBody()->on('data', function ($data) use (&$contentLength) {
$requestBody = $request->getBody();
$requestBody->on('data', function ($data) use (&$contentLength) {
$contentLength += strlen($data);
});

$request->getBody()->on('end', function () use ($resolve, &$contentLength){
$requestBody->on('end', function () use ($resolve, &$contentLength){
$response = new Response(
200,
array(
Expand All @@ -32,7 +33,7 @@
});

// an error occures e.g. on invalid chunked encoded data or an unexpected 'end' event
$request->getBody()->on('error', function (\Exception $exception) use ($resolve, &$contentLength) {
$requestBody->on('error', function (\Exception $exception) use ($resolve, &$contentLength) {
$response = new Response(
400,
array(
Expand Down
3 changes: 1 addition & 2 deletions src/Io/ChunkedEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public function handleEnd()
*/
private function createChunk($data)
{
$byteSize = strlen($data);
$byteSize = dechex($byteSize);
$byteSize = dechex(strlen($data));
$chunkBeginning = $byteSize . "\r\n";

return $chunkBeginning . $data . "\r\n";
Expand Down
4 changes: 2 additions & 2 deletions src/Io/RequestHeaderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ private function parseRequest($headers)
// parser does not support asterisk-form and authority-form
// remember original target and temporarily replace and re-apply below
$originalTarget = null;
if (strpos($headers, 'OPTIONS * ') === 0) {
if (strncmp($headers, 'OPTIONS * ', 10) === 0) {
$originalTarget = '*';
$headers = 'OPTIONS / ' . substr($headers, 10);
} elseif (strpos($headers, 'CONNECT ') === 0) {
} elseif (strncmp($headers, 'CONNECT ', 8) === 0) {
$parts = explode(' ', $headers, 3);
$uri = parse_url('tcp://' . $parts[1]);

Expand Down
3 changes: 1 addition & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ private function getConcurrentRequestsLimit()
}

$availableMemory = IniUtil::iniSizeToBytes(ini_get('memory_limit')) / 4;
$concurrentRequests = $availableMemory / IniUtil::iniSizeToBytes(ini_get('post_max_size'));
$concurrentRequests = ceil($concurrentRequests);
$concurrentRequests = ceil($availableMemory / IniUtil::iniSizeToBytes(ini_get('post_max_size')));

if ($concurrentRequests >= self::MAXIMUM_CONCURRENT_REQUESTS) {
return self::MAXIMUM_CONCURRENT_REQUESTS;
Expand Down