Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ini_set, set_time_limit, (max_execution_time) - not working

If I do set_time_limit(50) or ini_set('max_execution_time',50), then when I echo ini_get('max_execution_time') on my localhost i get 50, but when I do this on another server it echoes the default 30 and completely ignores my request. Why is this?

like image 823
Mickey Avatar asked Oct 19 '09 18:10

Mickey


People also ask

How to set execution time in PHP?

To increase the script execution time, you can use the following snippet at the top of your script. ini_set ( 'max_execution_time' , '300' ); In the above example, it would set the max_execution_time directive to 300 seconds.

What is max_execution_time in PHP INI?

max_execution_time int. This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30 . When running PHP from the command line the default setting is 0 .

What does set_time_limit 0 mean?

The purpose of this function is to set your PHP script execution time to a certain set period of time. The default is normally 30 seconds, but check your php. ini file to find out the default. Some developers set this to 0 which means the script execution time will not have a time limit imposed.


2 Answers

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

-- PHP manual, Runtime Configuration, description of max_execution_time

Many hosts run in safe mode. The other server is most likely one of them.

Edit: The same restriction is in place on set_time_limit:

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.

-- PHP manual, set_time_limit page

like image 100
Powerlord Avatar answered Sep 21 '22 08:09

Powerlord


Does GoDaddy allow you to edit their remote PHP.INI file, or (achieving the same function) set those options at runtime? Many restrictive hosts (and I don't know this about GoDaddy one way or the other) won't let you futz with PHP options either via the config file or at runtime as you did on WAMP. It could be that though you're still calling that function, it's not being applied.

Use

echo 'Time Limit = ' . ini_get('max_execution_time') .

The manual says that if it's set at all in the PHP.INI, that will override this runtime. PHP Manual on set_time_limit

like image 27
Alex Mcp Avatar answered Sep 18 '22 08:09

Alex Mcp