Page timing out with 404 error when script runs longer than 120 seconds

I have a script that needs to run for up to 15 minutes through a cron job. But I can't get the script to stay running. It errors out with a 404 message at exactly 120 seconds. Very strange. I have even called my hosting provider. I am at a loss.

I have set max_execution_time = 5000

Does anyone have any suggestions?

set_time_limit(0);

$array = array('1','2', '3');

foreach ($array as $row) {

    echo $row . '<br>';
                 sleep(50);

}


ANSWERS:


You may also need to look at Apache's timeout setting, as you can change the max execution time value in php.ini and still get stopped by Apache's timeout value in the httpd.conf file.

You can find httpd.conf by running httpd -V in terminal (The command name depends on your system/apache version, it can be also apache -V) ~ If you don't have terminal access, you may need to contact your webhost. Example output:

bash-3.2# httpd -V
Server version: Apache/2.2.22 (Unix)
Server built:   Aug 24 2012 17:16:58
Server's Module Magic Number: 20051115:30
Server loaded:  APR 1.4.5, APR-Util 1.3.12
Compiled using: APR 1.4.5, APR-Util 1.3.12
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/private/var/run/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"     <-- HERE IT IS

httpd.conf could look like this:

Notice the line:

Timeout 300


 MORE:


 ? Getting 404 error when submitting a form
 ? JSP in /WEB-INF returns "HTTP Status 404 The requested resource is not available"
 ? Tomcat started in Eclipse but unable to connect to http://localhost:8085/
 ? Why is @font-face throwing a 404 error on woff files?
 ? Routing for custom ASP.NET MVC 404 Error page
 ? How to check if a URL exists or returns 404 with Java?
 ? Best way to implement a 404 in ASP.NET
 ? How can I create an error 404 in PHP?
 ? How to get MVC action to return 404
 ? Image Get Requests with AngularJS