[php-src] Issue #11037: HTTP echo/output/cli webserver is quite slow
| From: | mvorisek | Date: | Fri, 07 Apr 2023 23:26:13 +0000 |
| Subject: | [php-src] Issue #11037: HTTP echo/output/cli webserver is quite slow | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244152@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11037
Author: mvorisek
### Description
The following code:
```php
<?php
$sizeMb = 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;
}
```
Webserver cmd:
```
php -S 1.2.3.4:9687 -t dir_path
```
Speedtest cmd:
```
wget -O/dev/null http://1.2.3.4:9687/test.php
```
Resulted in this output:
```
HTTP request sent, awaiting response... 200 OK
Length: 1073741824 (1.0G) [application/octet-stream]
Saving to: ‘/dev/null’
/dev/null 100%[=================================================>] 1.00G
159MB/s in 6.6s
2023-04-08 01:01:38 (156 MB/s) - ‘/dev/null’ saved [1073741824/1073741824]
```
But I expected this output instead:
We have a PHP app that can stream data at several GB/s, but as shown in the example above, PHP HTTP
echo/output/cli webserver is quite slow and I cannot get above about 150 - 170 MB/s.
Based on CPU usage I belive the bottleneck is in PHP and it is possible to improve it. I would
expect 1+ GB/s speed.
### PHP Version
*
### Operating System
tested on Windows and linux