0

I was dealing with a long-polling ajax script untill I realize the execution time of my php script NEVER ends. I did the following:

<?php
set_time_limit(11);
ini_set('max_execution_time',11);
echo ini_get('max_execution_time');

$i=0;
while (true) {
    $i++;
    echo "<br>".$i;
    sleep(1);
}
echo "END";
?>

I get the first line as I expected; "11". But the script is still counting... I keep the page echoing... I don't know when it will finish Any suggestion? I dont have access to the server, it is at ehost.com

Leonardo Javier
  • 89
  • 1
  • 2
  • 11
  • first is 11, after that 1 ...... 12, after that Fatal error: Maximum execution time of 11 seconds exceeded in C:\xampp\htdocs\php7\timeneverstop.php on line 7 What do you want? – b2ok Mar 16 '17 at 23:19
  • The script keeps counting... right know is echoing more than 800... so... – Leonardo Javier Mar 16 '17 at 23:20
  • It looks like it is OS-dependent - i.e., under Linux sleep() time is ignored so max_execution_time refers to real running time, not including sleeping time. See: http://stackoverflow.com/questions/740954/does-sleep-time-count-for-execution-time-limit – manassehkatz-Moving 2 Codidact Mar 17 '17 at 01:20
  • An sleep inside a While loop is a bad practice. But what is the code objective? – Jorge SB Sep 17 '17 at 04:39

1 Answers1

0

Check this docs.

Warning
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.

Maybe that is your issue. Anyway also from the safe mode's docs:

Warning This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

Condorcho
  • 503
  • 4
  • 12
  • That was the first I though, but in [php documentation](http://php.net/manual/en/features.safe-mode.php) says that "This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0" and my version is 5.6.29 – Leonardo Javier Mar 16 '17 at 23:30
  • [This](http://stackoverflow.com/questions/12094839/php-set-time-limit-does-not-work-safemode-is-off) might help you too. – Condorcho Mar 16 '17 at 23:33
  • Also [check this](http://stackoverflow.com/questions/7493023/why-doesnt-set-time-limit-work-as-expected), especially [this answer](http://stackoverflow.com/a/7493056/7431119) – Condorcho Mar 16 '17 at 23:38
  • for sure that should be the problem.... the sleep function doesn't count... finally it finish in 2753. thanks! – Leonardo Javier Mar 16 '17 at 23:55