Answer the question
In order to leave comments, you need to log in
PHP: echo is very slow
A strange problem, the simplest code:
echo $content;
Where $content = 100-110 kb of pure html - it takes almost a second!
I tried to create a separate page, where there are not even variables, just echo and 100 kb of text, it's still very slow.
In Google, such complaints are found, but all are dated 2005-2006 and the solutions come down to playing with output_buffering or splitting $content into parts, which does not help.
Dear Habrarazum, help, is echo really so slow, or is there something to fix in the conservatory?
Answer the question
In order to leave comments, you need to log in
Almost certainly a problem with the webserver or maybe DNS?
gentoo, apache, slow old AMD Sempron(tm) Processor 3400+
a.php:
ps but if you have the same thing with cli php then you need to sound the alarm!!!
pps I had a moment at the first vds when the simplest lib_curl (more precisely, curl_... calls from php) mercilessly suspended the virtual machine at 100% for seconds, but at the same time, the curl / wget console utility worked without problems ... while I was generally figuring out where the brakes came from , the problem resolved itself (it lasted for hours), so I wrote down openvz (or rather virtuozzo) to the account of potential glitches and made a notch in memory that this is also possible. <?php echo str_repeat('0123456789012345',8192); ?>
# date; curl http://localhost/a.php >/dev/null;date
Втр Авг 9 20:15:03 NOVST 2011
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 128k 0 128k 0 0 31.4M 0 --:--:-- --:--:-- --:--:-- 41.6M
Втр Авг 9 20:15:03 NOVST 2011
ADF: The problem is localized, and it's not in PHP: any webserver gives a static file of 100 kb for about a second. Both ngix and apache. Both have almost zero load.
Is it executed starting from the moment of the request from the browser?
There is still a lot to work out before echo, starting with the web server.
You need to check everything, calculate exactly where the delay is.
How do you measure execution time? Are you running through the console or through the browser?
I don't know how you measure, try this.
<?PHP
$start = microtime();
// Твое ехо
$end = microtime();
echo 'Время - ' . ($endtime - $starttime) . ' микросекунд';
?>
Tell us more about the server on which you are testing all this. Interested in his hardware, operating system, current load.
APD2: If you run the script from the console, it takes 2.2 seconds (one big echo in the script). And if you redirect the output to /dev/null, and microtime to error_log, then it takes 0.003 seconds
Considering the fact that it slows down, you should check the disk system and the Internet channel, it makes sense to execute locally ab. In general, I would advise starting with strace, it will show the execution time of system calls well, there can be many problems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question