Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP- cannot change max_execution_time in xampp

I've tried everything to change the max_execution_time of a php crawler script so that it can run an infinite amount of time.

I have changed the php.ini file setting max_execution_time to 0 or 100000000 but with no change

I've also tried setting it from the php script itself by using ini_set('max_execution_time', 0);

All php scripts throw the same error Fatal error: Maximum execution time of 3000 seconds exceeded, what could I be missing and how can I make sure there is no max execution time limit?

php script

<?php
ini_set('MAX_EXECUTION_TIME', -1);
error_reporting(E_ALL);  // turn on all errors, warnings and notices for easier debugging
//ini_set('max_execution_time', 123456);
ini_set('max_input_time', -1);
ini_set('memory_limit', '512M');
set_time_limit(0);
date_default_timezone_set('Europe/London');

/*code which scrapes websites*/

?>

phpinfo()

max_execution_time  0   0
max_input_time     -1   -1
like image 341
mk_89 Avatar asked Jul 01 '12 18:07

mk_89


People also ask

What is the maximum value of max_execution_time?

ini_set('max_execution_time', 108000); which equals to 30 hours.

What is set time limit in PHP?

The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php. ini . When called, set_time_limit() restarts the timeout counter from zero.


3 Answers

Try turning off safe mode in php and then try the below code

if( !ini_get('safe_mode') ){ 
    set_time_limit(0); //this won't work if safe_mode is enabled.
}

This should allow you to run the script for infinite time.

In Apache you can change maximum execution time by .htaccess with this line

php_value max_execution_time 200

set_time_limit() php manual ref.

like image 154
LoneWOLFs Avatar answered Oct 10 '22 17:10

LoneWOLFs


You shouldn't let your crawler run under apache, it's better to run it stand-alone via cli as part of a Gearman setup.

That way it won't hog your web server and it can run as long as you want. You can find many bindings for Gearman that you can use, including PHP of course.

like image 26
Ja͢ck Avatar answered Oct 10 '22 16:10

Ja͢ck


use

set_time_limit(0);

at the top of the script

like image 32
Learner Avatar answered Oct 10 '22 17:10

Learner