Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP script ignores max_execution_time and stops at the 600th second

Script runs on shared hosting and obeys the root php.ini file. It uses PHP 5.4 so there's no safe_mode and it's not using .htaccess files. I asked support if they have any limits, she said the timeout is two hours on their side. On localhost it doesn't stop but ignores my limits.

This example stops after 601-606sec (~10min) instead of 1000sec:

// For immidiately printing in browser
header('Content-Type:text/html; charset=UTF-8');

$limit = 1000;

set_time_limit($limit);
ini_set('max_execution_time', $limit);
ini_set('max_input_time', $limit);
ini_set('memory_limit', $limit . 'M');
ini_set('max_input_time', $limit);
ini_set('post_max_size', $limit);
ini_set('file_uploads', $limit);
ini_set('upload_max_filesize', $limit);

$start = microtime(1);

// Every second prints elapsed seconds
for ($i=0; $i<1000; $i++){
    echo str_pad(round(microtime(1)-$start), 4096);
    flush();
    sleep(1);
}
  1. Most important question is why it stops? I don't need 2 hours but 20-30min will be nice.
  2. Why it ignores my limits? I can change $limit to '1' but it will change nothing.
like image 414
mu3 Avatar asked Jan 24 '26 20:01

mu3


1 Answers

First about timeouts:

set_time_limit() and max_execution_time don't count sleep(), system(), file_get_contents() and DB calls. That's why I thought the script ignores my limits.

I talked again to support and turned out that what stops the script is not Apache timeout but «something» that monitors scripts and stops it after 10 minutes for shared IP customers. I asked him for full list of limits:

Type       | Dedicated | Shared
-----------+-----------+-----------
Apache/Web | 12 hours  | 10 minutes
SSH/Shell  | 2 hours   | 1 hour
Cron Jobs  | 1 hour    | 30 minutes
Daemons    | Unlimited | 10 minutes

That's why it ran fine from the cron.

like image 130
mu3 Avatar answered Jan 27 '26 12:01

mu3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!