php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18029 Echoing long strings :: long echo times over a number of characters
Submitted: 2002-06-27 19:43 UTC Modified: 2002-06-28 00:54 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: wrestlecar at hotmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 4.2.1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wrestlecar at hotmail dot com
New email:
PHP Version: OS:

 

 [2002-06-27 19:43 UTC] wrestlecar at hotmail dot com
I have discovered a problem that is most likely related to PHP and the echo statement, but it is possible that it is a server configuration issue as well.

When echoing long strings, the server has no problem until it gets to a certain window of characters, this ranges depending on the load of the server but is usually around 15,000 characters. For example, take a look at these page generation times for a custom script that was developed to investigate this issue( the load average on the server was about the same when all tests were taken). The times listed below are simply to echo one string with the number of characters indicated.

Display Length: 14201 characters.
Display Output: 0.00199 seconds.

Display Length: 14251 characters.
Display Output: 0.00159 seconds.

Display Length: 14301 characters.
Display Output: 0.12694 seconds.

Display Length: 14401 characters.
Display Output: 0.13424 seconds.

Now, getting to the really awkward part. If the string is "exploded" by linebreak, and then echoed in a loop line by line, the processing time is roughly 4x FASTER than that of echoing the single statement, this has been verified by another script I developed.

This behavior is not present on everyone's system, it has been tested on several systems using the same script and this was the worse case, while some other systems did display similar results.

Here is the test script that was used to identify the problem:

<?php
for( $i = 0; $i <= 20000; $i++)
{
   $example_output .= '1';
}

$microtime = explode(' ', microtime());
$startTime = $microtime[0] + $microtime[1];
echo $example_output;
$microtime = explode(' ', microtime());
$endTime = $microtime[0] + $microtime[1];
echo 'Display Length: ', strlen($example_output), ' characters.<br>';
echo 'Display Output: ', round($endTime - $startTime, 5), ' seconds.';
?>

In the script, simply replace the 20000 with whatever number you wish to check.

Below are a few posts I made on forums inquiring about this issue, and may provide some small details by the other users that I did not pick up on.

http://www.sitepointforums.com/showthread.php?threadid=65280
http://www.invisionboard.com/forums/index.php?s=&act=ST&f=7&t=12538

Unfortunately, since the server is not my own and is a shared server, I do not have a list of the modules PHP was installed with, but here is some information on the server.

Status: http://dragon.nocdns.com
PHPInfo: http://dragon.nocdns.com/phpinfo/

Thank you for your assistance.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-28 00:54 UTC] wrestlecar at hotmail dot com
It appears the issue is related to the Nagle Algorithm and how it affects TCP/IP transmissions of small packets done separately versus large packets.
 [2002-07-10 13:54 UTC] van dot binsbergen at taktik dot ch
Hi wrestlecar

Very glad I found someone who met this problem also! I found on my system (also using 4.2.1) that the "breakpoint" is exactly at 8182 characters! (Where as this seems to be about 15000 in your system).

>It appears the issue is related to the Nagle Algorithm and how it
>affects TCP/IP transmissions of small packets done separately versus
>large packets.
Maybe, but it is a bug anyway! 

Urs
 [2021-01-25 20:46 UTC] php4fan at gmail dot com
F*****g unbelievable.

It's been EIGHTEEN and a half year, and this is still an issue.

Why the **** was this closed?

So what if this is due to Nagle's Algorithm?? Just split the string into smaller ones and send them! It fixes the issue if I do that in my code, so why shouldn't you just do it internally?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC