Friday, January 16, 2026
HomeLanguagesHow is it possible to set an infinite execution time for PHP...

How is it possible to set an infinite execution time for PHP script ?

Yes, it is possible to set an infinite execution time for the PHP Script. We can do it by adding the set_time_limit() function at the beginning of the PHP script.

The set_time_limit() function takes only one parameter that is int value which is in seconds and it returns a boolean value. If the script reaches the amount of time given, then it gives a fatal error.

Syntax:

set_time_limit ( int $seconds )

Return Value: Boolean ( True or False )

Default value:30 seconds

For the maximum or you can say for the infinite execution time, we can set the function with the 0 value. If the value is 0 then it will run for an infinite time.

Note: This method will only work if you are allowed to change PHP configuration by the Hosting Server.

 Example 1: The following example is of setting the execution time to 40 seconds

PHP




<?php
    
    // This will set the time limit to 40 seconds 
    // Default time is 30 seconds
    set_time_limit(40);
    $j=1;
    while($j<5)
    {
       echo "$j, ";
       $j++;
     }
?>


Output:

 1, 2, 3, 4,

Examples 2: The following example is of the setting time to maximum(infinite) time.

PHP




<?php
    
    // This will set the time limit to infinite (maximum) 
    // Default time is 30 seconds
    set_time_limit(0);
    $j=1;
    while($j<50){
     echo "$j, ";
     $j++;
   }
?>


Output:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49,
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32470 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6837 POSTS0 COMMENTS
Nicole Veronica
11972 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12052 POSTS0 COMMENTS
Shaida Kate Naidoo
6972 POSTS0 COMMENTS
Ted Musemwa
7211 POSTS0 COMMENTS
Thapelo Manthata
6925 POSTS0 COMMENTS
Umr Jansen
6904 POSTS0 COMMENTS