SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    528
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    php & cron timing out

    My understanding of running php scripts under cron was that they weren't subject to the normal php script timeout. Is this not the case?

    I have, in the past, run scripts that must have taken a few minutes at least, but a cron job I ran today said it timed out after 30 seconds.

    Please someone set me straight - If you want to run an autonomous and long-running process can you use cron & php?

  2. #2
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, you can run PHP under cron. But when it starts up, PHP will read its php.ini and the default time limit is 30 CPU seconds. To change the limit, you need to change the max_execution_time value in the php.ini file or use ini_set() to change the value. I may be wrong but I think a value of zero disables the time limit.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    scripts ran via php's CLI by default have no timeout. often scripts ran via cron are run using CLI.


    i bet you are running them with wget, which is the same as if a browser called the script.

    so look at set set_time_limit()

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The PHP CLI isn't subject to a maximum execution time. The time out could be cause by it exceeding the max_input_time if it's reading in large amounts of data. What's the exact error message you get?

  5. #5
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    528
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    The error was:

    Fatal error: Maximum execution time of 30 seconds exceeded in [file name] on line 75

    This is having done 1500 of the 13000 run. I'll check the server setup and whether set_time_limit() has any effect.

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2003
    Location
    United Kingdom
    Posts
    2,120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use to do php by browser, but made it automated. I asked people if it would timeout as I will have a script running for sometime by cron. The answer was that it would not time out.

    So I was happy with that. I done my script and found that it just timed out after 30 seconds. I then had to include set_time_limit(18000); near the top of my php script and now it does not time out.

    If I am right, I think I have set it to about 5 hours, could someone confirm that for me as I may have to increase it again soon. lol

    Also, I would like to KNOW if mysql will time out as I want to select over 3,000,000 rows of data from one mysql table and insert it into another while it also does a few things first. So does MYSQL time out using cron?

    Thanks for your help.

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by john278
    So I was happy with that. I done my script and found that it just timed out after 30 seconds. I then had to include set_time_limit(18000); near the top of my php script and now it does not time out.

    If I am right, I think I have set it to about 5 hours, could someone confirm that for me as I may have to increase it again soon. lol
    18000 / 60 = 300 minutes
    300 / 60 = 5 hours

    Quote Originally Posted by john278
    Also, I would like to KNOW if mysql will time out as I want to select over 3,000,000 rows of data from one mysql table and insert it into another while it also does a few things first. So does MYSQL time out using cron?
    The resources your PHP script uses (such as a database connection handle) are not removed until the end of execution during GC. Your connection shouldn't disappear arbitrarily.

  8. #8
    SitePoint Wizard
    Join Date
    Nov 2003
    Location
    United Kingdom
    Posts
    2,120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


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
  •