php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71420 Can't echo very large strings
Submitted: 2016-01-20 14:12 UTC Modified: 2016-01-21 05:50 UTC
From: mark at interactivedimension dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.6.17 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mark at interactivedimension dot com
New email:
PHP Version: OS:

 

 [2016-01-20 14:12 UTC] mark at interactivedimension dot com
Description:
------------
Hi

I'm not sure if this is a php bug or some kind of server config.

The script below will not run on my shared server at all. It will however work on my local machine.

It will output a string of up to approx 2million characters but there comes a point where the page just hangs and never loads.

I can't figure out a way around this. I've tried breaking the string into smaller parts but I can only output so much before the same thing happens.

Test script:
---------------
<?php

$data = '';

for($i = 0; $i < 3000000; $i++) {
	$data .= 1;
}

echo $data;

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-20 15:33 UTC] rasmus@php.net
-Status: Open +Status: Feedback
 [2016-01-20 15:33 UTC] rasmus@php.net
Anything in your error log? You could be hitting a configured memory limit.
 [2016-01-20 16:10 UTC] mark at interactivedimension dot com
-Status: Feedback +Status: Open
 [2016-01-20 16:10 UTC] mark at interactivedimension dot com
Nothing at all. I don't get any errors on screen either.
 [2016-01-20 18:34 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2016-01-20 18:34 UTC] requinix@php.net
To be clear: you're saying the page *hangs*, meaning it never completes? Or it completes but leaves an empty page? And is that number near 2 million or 2 *billion*?

What about

<?php

error_reporting(-1);
ini_set('display_errors', true);

echo "start<br>\n"; flush();

$data = '';
for($i = 0; $i < 3000000; $i++) {
	$data .= 1;
}

echo "end<br>\n"; flush();
echo $data; flush();

?>
 [2016-01-20 21:36 UTC] mark at interactivedimension dot com
-Status: Feedback +Status: Open
 [2016-01-20 21:36 UTC] mark at interactivedimension dot com
2 million. And the page hangs, never completes. Bizarrely if I view the same page, using the same wifi connection on a mobile it loads in under a second.
 [2016-01-20 23:00 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2016-01-20 23:00 UTC] rasmus@php.net
This doesn't seem like a PHP problem then. PHP has no idea, and doesn't in any way care what kind of client is used for the request. If one works and another doesn't, the problem is elsewhere.
 [2016-01-20 23:20 UTC] mark at interactivedimension dot com
I'm not sure. I can do pretty much anything with the string except echo it. I can write it to a file for instance, but I can't use readfile() and output it on screen, it's really weird. Although I can do all this on my local machine with no errors.

I've read elsewhere that it may have something to do with Nagles Algorithm and tcp/ip buffering, but that's a bit over my head.

I've been through all the settings on the server that I can think of but nothing is fixing it.
 [2016-01-21 05:50 UTC] rasmus@php.net
Right, but you are getting into technical support questions here and this is a bug tracker. PHP doesn't do the actual network communications. Your web server and operating system does that. There is nothing here that indicates a PHP bug of any kind.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC