-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add curl handler streaming support #3115
Copy link
Copy link
Closed
Labels
lifecycle/staleNo activity for a long timeNo activity for a long time
Description
Feature request
Based on the discussione below, it seems the main bottleneck is caching the whole response thru disk. This issue is therefore a feature request to add streaming support for curl handler.
Guzzle version(s) affected: any (6.5, 7.5)
PHP version: any
cURL version: any
Description
PHP internal webserver can serve data at >4 GB/s speed. The biggest bottleneck is Guzzle client which seems to be capped around 500 MB/s.
How to reproduce
Server side:
server.php
<?php
$sizeMb = 1 * 1024;
$sizeBytes = $sizeMb * 1024 * 1024;
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $sizeBytes);
header('Content-Disposition: attachment; filename="test.bin"');
$string = str_repeat(bin2hex(random_bytes(128)), 256); // 64 kB
for ($i = $sizeBytes / strlen($string); $i >= 0; $i--) {
echo $string;
}
cmd:
php -S 127.0.0.1:9687 -t dir_path
Client side:
public function testHugeOutputStream(): void
{
$client = new \GuzzleHttp\Client();
$sizeMb = 1 * 1024;
$sizeBytes = $sizeMb * 1024 * 1024;
$response = $client->request('GET', 'http://127.0.0.1:9687/demos/_unit-test/stream.php');
static::assertSame(200, $response->getStatusCode());
static::assertSame('application/octet-stream', $response->getHeaderLine('Content-Type'));
static::assertSame((string) $sizeBytes, $response->getHeaderLine('Content-Length'));
$stream = $response->getBody();
$length = 0;
while (!$stream->eof()) {
$length += strlen($stream->read(16 * 1024));
}
static::assertSame($sizeBytes, $length);
}
The test pass, but the typical run time is around 2.2 secs on both Windows and linux. I would expect >2GB/s.
Possible Solution
Maybe the response is internally read in small receive buffers etc., IDK.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
lifecycle/staleNo activity for a long timeNo activity for a long time