1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Prevent Apache HTTP timeout when running PHP script?

Discussion in 'PHP' started by feonix, Jan 13, 2009.

  1. #1
    I have a script that will take a few hours to finish running.

    The problem is that after 10 minutes the script is stopped due to timing out in Apache I'm asssuming. I have hostgator as a host and they refuse to let me change the timeout settings for Apache or PHP.

    How can I let this script finish running and not have Apache timeout and stop it?

    I've even tried running the script from the command line using a cron job and it just times out after 30 seconds which is the PHP timeout limit. When I run the script in the browser it seems to be able to bypass this limit but then runs into the 10 minute Apache limit.

    I'm assuming I need some way for the page itself to be "done" loading while the script continues to run and then the page refreshes and shows the new output or something like this.

    This is driving me INSANE. Please help.
     
    feonix, Jan 13, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    PHP automatically disables the time limit when running in command line mode, are you sure this is the error?

    Try.

    set_time_limit(0);
    PHP:
     
    Danltn, Jan 13, 2009 IP
  3. feonix

    feonix Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes I spoke with hostgator and they said there is a 30 second maximum execution time for PHP and it can't be changed.

    I had my script output to an html file that had a meta refresh in it then I created a cron job to run it. I watched the output file refresh every 5 seconds for 30 seconds then stop. When I run the script in the browser it runs completely fine for exactly 10 minutes.

    I already have set_time_limit(0); in the script.
     
    feonix, Jan 13, 2009 IP
  4. tradeout

    tradeout Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    A few hours?!

    Have you thought about breaking the php script up and creating an Ajax script to call the php each time it finishes a part?
     
    tradeout, Jan 13, 2009 IP
  5. linkexchange1984

    linkexchange1984 Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    linkexchange1984, Jan 13, 2009 IP
  6. livedating

    livedating Active Member

    Messages:
    161
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    83
    #6
    You can also edit php.ini:
    ...
    max_execution_time = 60 ; Maximum execution time of each script, in seconds
    max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
    ...
     
    livedating, Jan 13, 2009 IP
  7. feonix

    feonix Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ^^ Looks like neither of you even read the thread because I already said I have set_time_limit(0); and that my host has locked the max execution time.

    Please read before responding next time. Not trying to be rude or anything but don't just respond without understanding the situation because it makes you look like a post whore.

    I'll look into this but it's kind of difficult as the script only really breaks up into different parts that could take over 10 minutes to complete.
     
    feonix, Jan 13, 2009 IP
  8. artflutter

    artflutter Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #8
    If you don't want to edit the script then I guess you'd have to change hosts.
    a few hours is a very long time, surely you can break it up a bit, what does it do?
     
    artflutter, Jan 13, 2009 IP
  9. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #9
    Move the script to a host that will allow the script to finish ?

    If Hostgator has disabled your ability to extend script execution times, and you do find some sort of workaround, you're probably going to run into problems along the lines of your account being suspended or being right back where you are now when their administrators start wondering why there's lingering processes slowing down their servers and trace it back to you.
     
    joebert, Jan 13, 2009 IP
  10. Jeremy Morgan

    Jeremy Morgan Peon

    Messages:
    322
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I have used

    
    
    ini_set('max_execution_time', '3600');  
    
    
    PHP:
    3600 = 3600 seconds.
     
    Jeremy Morgan, Jan 17, 2009 IP
  11. yugu

    yugu Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    The solution can be to rewrite the script dividing it into fast accomplished parts. The parts can call each other so the process does not stop.
    Or find another hosting provider, maybe switch to VPS plan.
     
    yugu, Jan 18, 2009 IP
  12. Linked2K

    Linked2K Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I recommend you to get a VPS, you can configure your own limits then.
    [​IMG]
     
    Linked2K, Jan 18, 2009 IP