php.ini file defines the maximum number of seconds a PHP script can run. If your script exceeds the time then web server will send a request timeout HTTP response error.
You can change the script execution time using this one line of code
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
Put this code in the beginning of your script.
If you want to run the script infinitely then turn of script execution time limit feature using this one line of code