SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Does Apache TimeOut directive affect PHP scripts running as cron jobs?

    Hi. My first post .

    I'm working on a php script for a client, brief description is that it goes out to a bunch of sites and downloads information about products, including quite a few images, which it then resizes (creating thumbnails, etc). The gist is it takes a while to run, and I'm noticing it's timing-out at about 5 minutes.

    My client uses godaddy for hosting, and my guess is their apache Timeout is set to 5 minutes. Unfortunately I cannot seem to override this in a .htaccess (which would be nice to test whether this is really the issue or not).

    My question is , would this Apache Timeout even affect a PHP script running as a cron job (eg .../bin/php5 myscript -dot - php). I'm setting up the cron job via godaddy's control interface (since ssh access is not enabled, another bummer as I can't even invoke the script directly to test it).

    I called set_time_limit(10*60) in the script itself, which should allow php itself to run for 10 minutes. Basically, I'm trying to determine if Apache is the issue. If so I need to redesign around the fact that I can't override it.

    Helo

    ps--I called godaddy support and they did not give me much help on a technical level.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The PHP binary does not read Apache configuration files, so no, no Apache setting is going to influence when your script times out.

  3. #3
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply Dan.

    One small correction to my original post, the cron is invoked as follows:

    /web/cgi-bin/php5 "$HOME/my_script -dot- php"
    (I'm spelling out dot because I have under 10 posts here and otherwise it's interpreted as a web address)

    I'm not sure if this means the binary is php-cgi or php. Would this make a difference in terms of timeouts?

    Thanks,

    Helo

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's the program "php5" running your program, not Apache, and PHP doesn't know anything about Apache's configuration files. The only configuration that will be used in executing your script is php.ini and any directives in the code.

  5. #5
    Non-Member adstiger's Avatar
    Join Date
    Nov 2008
    Location
    Canada
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you access it through http in your cronjob, then it will work as a webpage request and then it may be affected by apache timeout because apache is involved in the process. You can run the php script directly with an absolute path using php interpreter to bypass apache.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you maybe running out of memory? Turn error reporting up and make sure errors get logged to a file. You could maybe use register_shutdown_function() to try to write some debug data to a file right before the script dies.

    You might also wanna see if the webhost might have something running which kills processes which run too long(or maybe uses too much cpu/memory). You might be able to install a SIGTERM handler to try to catch that signal and log this condition. That would make it pretty obvious something killed the process. You can't catch all signals though, but SIGTERM is probably what they would use, and you can catch that one. see pcntl_signal()

    A quick thing you could do is just make a dummy script which does nothing but loops, appending a timestamp to a log file. see how long the script stays alive for. make sure you sleep() a bit in between loops....

  7. #7
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thanks for the replies.

    Catching a kill signal if that's what is happening would be useful. However the script failed immediately when I added pcntl_signal() complaining it couldn't find the function. I didn't have time to investigate yet, could be godaddy doesn't have that module available (I didn't see it on phpinfo)?

    The reason I was asking about php-cgi is that on another thread someone mentioned that a 5-minute timeout existed for "Server API CGI/FastCGI":

    (see Posts #6 and #7 on the thread. I can't post URL because its being filtered out, but the title is : "PHP script timeout while reading large file". t=553824)

    They were referring to IIS on that thread, but I was wondering if a similar issue may apply to Apache.

    When PHP times out due to reaching its own max_execution_time, it sends an error such as:
    Fatal error: Maximum execution time of 10 seconds exceeded in my_script -dot- php on line 82

    (I purposely set it to 10secs this one time to force the issue and see what would happen.) The thing is I don't see this error or any similar error when my script times out under normal circumstances (I set max_execution_time to a very high number when running). I'm assuming this rules out PHP failing due to reaching some max value set in php -dot- ini?

    So basically, I've ruled out (or am trying to rule out) php limits, apache timeouts, and trying to confirm if there is a signal coming from the host that is causing my script to end prematurely.

    I'll look at memory as well as crmalibu mentioned, but wouldn't PHP dump an error somehwere if this was the case?

    Thanks,

    Helo

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Reaching the maximum memory limit set in php.ini should also cause a fatal error, so if you're able to capture errors already, that's probably not it.

    I'm going to say your host killing the process through some automatic monitor is becoming the most likely scenario.

    GoDaddy is really not a good place to host anything more than a 5-page brochure website. They sell hosting as a commodity, like domain names, not a service.

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by helo View Post
    They were referring to IIS on that thread, but I was wondering if a similar issue may apply to Apache.
    In case you missed it, the OP stated towards the end of the thread they was using godaddy also. So reason still unknown, but they had the same problem it seems.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •