I have a PHP script like this running on PHP-fpm 7.3:
<?php
$file = './French-Stories-Martine.zip';
if (headers_sent()) {
echo 'HTTP header already sent';
} else {
if (!is_file($file)) {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
echo 'File not found';
} else if (!is_readable($file)) {
header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
echo 'File not readable';
} else {
header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Length: ".filesize($file));
header("Content-Disposition: attachment; filename=\"".basename($file)."\"");
readfile($file);
exit;
}
}
?>
I've tried downloading this zip file statically (meaning without a PHP script - just using a plain old Apache + OpenLiteSpeed webserver), and the download speed is great. Nothing wrong with that.
The problem is when I'm trying to download the said zip file, with this PHP script. The download speed is 1/10th.
Now, I've concluded that the issue is with the PHP and not with the WebServer or the Server itself. I can't figure out what the problem could be with my PHP?
I'm using the following configuration for PHP-fpm:
pm.max_children = 80
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
This is the PHP log file when I'm trying to download from my script:
[08-Nov-2021 00:40:52] WARNING: [pool www] child 3267, script '/www/wwwroot/example.com/my-php-script-dl.php' (request: "GET /my-php-script-dl.php") executing too slow (31.192873 sec), logging
[08-Nov-2021 00:40:52] NOTICE: child 3267 stopped for tracing
[08-Nov-2021 00:40:52] NOTICE: about to trace 3267
[08-Nov-2021 00:40:52] NOTICE: finished trace of 3267
[08-Nov-2021 00:42:30] NOTICE: Reloading in progress ...
[08-Nov-2021 00:42:30] NOTICE: reloading: execvp("/www/server/php/73/sbin/php-fpm", {"/www/server/php/73/sbin/php-fpm", "--daemonize", "--fpm-config", "/www/server/php/73/etc/php-fpm.conf", "--pid", "/www/server/php/73/var/run/php-fpm.pid"})
[08-Nov-2021 00:42:30] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:42:30] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:42:30] NOTICE: fpm is running, pid 5317
[08-Nov-2021 00:42:30] NOTICE: ready to handle connections
[08-Nov-2021 00:42:44] NOTICE: Reloading in progress ...
[08-Nov-2021 00:42:44] NOTICE: reloading: execvp("/www/server/php/73/sbin/php-fpm", {"/www/server/php/73/sbin/php-fpm", "--daemonize", "--fpm-config", "/www/server/php/73/etc/php-fpm.conf", "--pid", "/www/server/php/73/var/run/php-fpm.pid"})
[08-Nov-2021 00:42:44] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:42:44] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:42:44] ERROR: Another FPM instance seems to already listen on /tmp/php-cgi-73.sock
[08-Nov-2021 00:42:44] NOTICE: fpm is running, pid 5539
[08-Nov-2021 00:42:44] ERROR: FPM initialization failed
[08-Nov-2021 00:42:44] NOTICE: ready to handle connections
[08-Nov-2021 00:45:18] NOTICE: Reloading in progress ...
[08-Nov-2021 00:45:18] NOTICE: reloading: execvp("/www/server/php/73/sbin/php-fpm", {"/www/server/php/73/sbin/php-fpm", "--daemonize", "--fpm-config", "/www/server/php/73/etc/php-fpm.conf", "--pid", "/www/server/php/73/var/run/php-fpm.pid"})
[08-Nov-2021 00:45:18] ERROR: Another FPM instance seems to already listen on /tmp/php-cgi-73.sock
[08-Nov-2021 00:45:18] ERROR: FPM initialization failed
[08-Nov-2021 00:45:18] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:45:18] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:45:18] NOTICE: fpm is running, pid 6200
[08-Nov-2021 00:45:18] NOTICE: ready to handle connections
[08-Nov-2021 00:45:44] NOTICE: Reloading in progress ...
[08-Nov-2021 00:45:44] NOTICE: reloading: execvp("/www/server/php/73/sbin/php-fpm", {"/www/server/php/73/sbin/php-fpm", "--daemonize", "--fpm-config", "/www/server/php/73/etc/php-fpm.conf", "--pid", "/www/server/php/73/var/run/php-fpm.pid"})
[08-Nov-2021 00:45:44] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:45:44] NOTICE: using inherited socket fd=8, "/tmp/php-cgi-73.sock"
[08-Nov-2021 00:45:44] ERROR: Another FPM instance seems to already listen on /tmp/php-cgi-73.sock
[08-Nov-2021 00:45:44] ERROR: FPM initialization failed
[08-Nov-2021 00:45:44] NOTICE: fpm is running, pid 6251
[08-Nov-2021 00:45:44] NOTICE: ready to handle connections
[08-Nov-2021 00:47:46] NOTICE: Finishing ...
[08-Nov-2021 00:47:46] NOTICE: exiting, bye-bye!
[08-Nov-2021 00:47:47] NOTICE: fpm is running, pid 6518
[08-Nov-2021 00:47:47] NOTICE: ready to handle connections