1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Where can I host a long running php script?

Discussion in 'General Programming Chat' started by Highschooled, Jun 1, 2015.

  1. Highschooled

    Highschooled Regular Member

    Joined:
    Jul 31, 2011
    Messages:
    299
    Likes Received:
    398
    My official hosting is hostwinds, but I have a php script I'm running that goes through lists for me, pretty simple stuff but the script will take hours (huge list) and hostwinds is set to timeout scripts after 5 minutes and send a 500 internal error message.

    "This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'."

    Where can I host this php script so that it can run for as long as it needs to?
     
  2. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    974
    Likes Received:
    680
    Occupation:
    Web/Bot Developer
    Chunk up your processes. Instead of running one process on the entire list use cronjobs to launch your PHP script every X amount of minutes and have your script only process a small portion of the list. Like this you can run through your entire list over the course of a day without exceeding the 5 minute timeout.
     
  3. Repulsor

    Repulsor Power Member

    Joined:
    Jun 11, 2013
    Messages:
    770
    Likes Received:
    278
    Location:
    PHP Scripting ;)
    Almost all hosts have the timeout set at 10 minutes. PHP default timeout may be set to 30 seconds, which can be bypassed by using set_time_limit, which will then give us the maximum possible time for execution, say 5 in your case.

    The only possible way to make a way through this is to split the whole work into chunks. If it processes a file, set a cron that runs every minute and process a part of the array. Likewise, with designing a better workflow, you can get the stuff done without hitting the time limit.

    Pretty sure that you can optimize the code. I will take a look if you want.

    Cheers!
     
  4. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    3,476
    Likes Received:
    3,103
    Gender:
    Male
    You have some options.
    1. Set set_time_limit to 0 from php.ini
    2. Run your script as a cron job from terminal. When you run from terminal, there's no timeout.
    3. Break your script and go for some data in each run. This can be done simply by making a database table for your data, setting all jobs to not processed at first, and setting them processed once you process each one. Then just call select * from jobs where processed = 0.
     
  5. peetrike

    peetrike Power Member

    Joined:
    Aug 19, 2012
    Messages:
    585
    Likes Received:
    219
    Location:
    Estonia
    Use WAMP and your own PC/laptop.

    Cheers
     
  6. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,612
    Likes Received:
    11,239
    Occupation:
    Pusillanimous Knitter
    Location:
    Buenos Aires
    Get a VPS instead of shared hosting.
     
  7. nidhal

    nidhal Newbie

    Joined:
    Jun 13, 2010
    Messages:
    40
    Likes Received:
    5
    The best solution would be a VPS, you can customise PHP settings as you wish. Also VPS are cheap