diff --git a/examples/09-stream-request.php b/examples/09-stream-request.php index af4fb580..07cd21ed 100644 --- a/examples/09-stream-request.php +++ b/examples/09-stream-request.php @@ -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( @@ -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( diff --git a/src/Io/ChunkedEncoder.php b/src/Io/ChunkedEncoder.php index c075bdbc..8a7f8cfb 100644 --- a/src/Io/ChunkedEncoder.php +++ b/src/Io/ChunkedEncoder.php @@ -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"; diff --git a/src/Io/RequestHeaderParser.php b/src/Io/RequestHeaderParser.php index 21d2d322..23183fe5 100644 --- a/src/Io/RequestHeaderParser.php +++ b/src/Io/RequestHeaderParser.php @@ -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]); diff --git a/src/Server.php b/src/Server.php index 999409b3..d413bddf 100644 --- a/src/Server.php +++ b/src/Server.php @@ -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;