tags:

views:

48

answers:

2

This one really has me stumped. I have not ran across this problem on any other servers I have worked on.

This is on an Ubuntu 10.04.1 LTS server with PHP 5.3.2-1ubuntu4.5.

When I have a PHP script that does not have any output for over 120 seconds, the script will not show any subsequent output; however, any non-output will still be executed. This happens for both php5-cgi & php5 (cli). For example:

1. $iSleep = 120;
2. echo 'Now: '.date('H:i:s')."\n";
3. echo 'Sleeping for: '.$iSleep."\n";
4. echo 'Will wake up at: '.date('H:i:s', (time()+$iSleep))."\n";
5. sleep($iSleep);
6. echo 'Woke up at: '.date('H:i:s')."\n";
7. mail('[email protected]', 'Subject', 'Message');

I will get all the output back to the screen through line 4. Line 6 will never appear on the screen, but I will get an email from line 7. If I change line 1 to be 119 or less, the code will execute fully as expected. Please let me know if there are any other settings (php.ini) or version numbers that you want to know. Thanks in advance for your time.

A: 

My answer is also mostly a guess but you have the normal max_execution_time variable. By default, this is 30 as per the documentation. But one caveat it mentions:

The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.

I am positive mail() is a system call, thus you want to use set_time_limit as described.

Hopefully this solves your issue.

Bartek
These were both my primary suspects when the problem first surfaced, but adjusting both of them has not helped.
Daniel
My php.ini currently has max_execution_time = 0 and the script it self has set_time_limit(0);
Daniel
Have you tried adding a few flush()/ob_flush() calls in there? Could be getting caught up in Apache somewhere
Marc B
I tried this on the command line version as well (no ties to Apache or lighttpd). Same results.
Daniel
A: 

PHP appears to respond properly when I connect from other clients. I need to figure out what makes the client I am connecting from different.

Daniel