MarkTierney's avatar

Can't echo php string because it's too long?

Hi I've tried asking this on stackoverflow to no avail so I thought I'd try here.

I have a problem on my live server where the script below won't run and just causes the page to hang. If I reduce the number of loops to 2,000,000 it works. So i'm guessing there's some config I need to change. However I've upped everything I can think of to accommodate long running scripts, file uploads, max request size etc and nothing is working.

Any help or suggestions would be greatly appreciated!

$data = '';

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

echo $data;

0 likes
6 replies
ohffs's avatar

Apart from wondering why you're wanting to do this... you've set max_execution_time in your php.ini file and restarted apache/nginx/php-fpm? And have you looked in your webserver error logs?

MarkTierney's avatar

Haha, i'm outputting a virtual file tree with lots of files with long names!

The problem boils down to the length of the string (lots of nested unordered lists) I'm trying to output.

I've checked my error_logs and there's nothing there. I've gone through all my php ini settings and set them to at least what my local machine is set to. Plus if the string is 2 million characters long it executes in under a second so I'm sure it's not a time thing.

Thanks for your answer though!

MarkTierney's avatar

What is bizarre is that the script loads fine if I view it on the same network on an iphone!

ohffs's avatar

Maybe some odd browser thing then - do your dev-tools say anything helpful? If there's nothing in your logs then it's probably not ram either. Oddness!

MarkTierney's avatar

Yeah but it loads fine in the same browsers on my local machine. Oddness indeed!

Please or to participate in this conversation.