search for in the  
<set_magic_quotes_runtimeversion_compare>
Last updated: Thu, 19 May 2005

set_time_limit

(PHP 3, PHP 4, PHP 5)

set_time_limit -- Limits the maximum execution time

Description

void set_time_limit ( int seconds )

Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

Warning

set_time_limit() 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.

Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.

See also: max_execution_time and max_input_time ini directives.



User Contributed Notes
set_time_limit
Jimmy Wimenta
23-Sep-2004 03:15
Referring the the last 2 comments about whether the duration of sleep() will be counted in execution time, the answer is it depends on the platform. In Linux it does not, while in Windows it does.
nathan
06-Apr-2004 05:04
unless I am doing something stupid, my testing (at least on php 4.3.4) seems to indicate that sleep() does indeed count towards script execution time, contrary to the previous post.

Here is my test code:

for ($i=0; $i < 10; $i++) {
   sleep(10);
   echo " [$i] ";
}

This will exceed execution time after only 2 loops.
riki1512 at gmx dot de
02-Apr-2004 07:26
The duration of the pause when calling the sleep() function is also not added to script-execution time.
php at mightycpa.com
26-Jun-2003 04:30
You may also need to look at Apache's timeout setting (Win32 version for me), I changed max execution time value in php.ini, and still got stopped by Apache's timeout value in the httpd.conf file.
rsallo at gna dot NOSPAM dot es
30-May-2003 07:28
When you are working with IIS, PHP timeout is valid only when it's lower than script timeout defined by IIS.

IIS 5 has a default timeout of 300 seconds. If you need a higher timeout, you also have to change IIS properties. Otherwise, your server will stop your PHP script before it reaches its own timeout.
16-Oct-2001 08:04
user abort stop the script
see "ignore_user_abort"

<set_magic_quotes_runtimeversion_compare>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 18:35:34 2005 EDT