Script execution time

21 replies
I have a php script that takes around 15 minutes to run. But the server cuts it off around the 5 minute mark. Is there a way to avoid the runtime error in php?
#execution #script #time
  • Profile picture of the author Cashmatic
    set_time_limit($seconds);
    You can find more detailed information about this function here:
    php.net/manual/en/function.set-time-limit.php

    Hope this helps!
    {{ DiscussionBoard.errors[2485721].message }}
    • Profile picture of the author Shounak Gupte
      Originally Posted by Cashmatic View Post

      set_time_limit();
      You can find more detailed information about this function here:
      php.net/manual/en/function.set-time-limit.php

      Hope this helps!
      thanks for the tip... will try it out tonight
      Signature
      Looking for a quality but affordable graphic designer to partner with. To express your interest PM me with some samples.
      {{ DiscussionBoard.errors[2488121].message }}
  • Profile picture of the author webfighter
    You need to have root access to your server. Increase the value of max_execution_time in your php.ini file.
    {{ DiscussionBoard.errors[2486381].message }}
  • Profile picture of the author Bruce Hearder
    A script that takes 15 minutes to run is IMHO not a good idea!
    Too many things can go wrong in that time (internet connections, server performance etc).

    It it possible to change the script so that it processed smaller blocks of data at a time, but ran more frequently.

    Just a thought

    Bruce
    {{ DiscussionBoard.errors[2489368].message }}
  • Profile picture of the author babypar
    I believe you can set this in the .htacess aswell
    Signature

    Double Links SEO Link Building Service. High TF, CF
    Backlink Case Study

    {{ DiscussionBoard.errors[2638718].message }}
  • Profile picture of the author phpbbxpert
    What kind of script are you running that takes 15 minutes to run?

    If it runs that long, there is either an issue or it is not programmed correctly.

    If it is doing a large task like backups or emails, then it should be limited with a timeout then restarted where it left off. But this should have been coded in if the script was coded correctly.
    {{ DiscussionBoard.errors[2639065].message }}
    • Profile picture of the author mojojuju
      I think if you run the script from the command line, the set max_execution_time doesn't apply. Can anyone confirm this?
      Signature

      :)

      {{ DiscussionBoard.errors[2639655].message }}
  • Profile picture of the author hhunt
    Any script that runs beyond 20 seconds needs a rework. If you are good at programming, try refactoring to make sure that it does not timeout. Again, if possible get someone else to help you review, improve and remove the bottleneck that's making it take that long to execute.

    Good luck
    {{ DiscussionBoard.errors[2642517].message }}
  • Profile picture of the author Silke
    You should investigate why the script is running so long, to me it is not normal.
    {{ DiscussionBoard.errors[2644490].message }}
  • Profile picture of the author cyphix
    Could you give us an idea of what the script does?
    {{ DiscussionBoard.errors[2644973].message }}
  • Profile picture of the author zeeshi570
    Yes you can increase runtime in php ini
    {{ DiscussionBoard.errors[2645057].message }}
    • Profile picture of the author hhunt
      Originally Posted by zeeshi570 View Post

      Yes you can increase runtime in php ini
      Increasing runtime is NOT the solution. The script needs refactoring. I've been programming for the last 9 years and have never seen anything that runs that long.

      Rewriting the script is the only solution otherwise your hosting company will eventually send you a warning.
      {{ DiscussionBoard.errors[2645739].message }}
  • Profile picture of the author SEOTranslator
    There must be something wrong with that script, unless you handle millions of records. There is no way that a normal script can take that much time...

    Have a look at it, if it runs for so long it will consume so much CPU time that you hosting provider might send you a warning, as indicated by hhunt.
    Signature
    Website localization and multilingual SEO
    Making your translated sites friendly for humans and machines alike.
    {{ DiscussionBoard.errors[2647228].message }}
  • Profile picture of the author cyphix
    I don't think we can speculate saying that it shouldn't be running that long etc until we know what it does..... if it's on the client end (highly unlikely) obviously it shouldn't run that long as otherwise the client wouldn't stick around lol..

    But it sounds like he is running it for processing something on his end, could be processing a lot of data from the database... which could very well then run for 15 minutes.
    {{ DiscussionBoard.errors[2649257].message }}
    • Profile picture of the author phpbbxpert
      Originally Posted by cyphix View Post

      I don't think we can speculate saying that it shouldn't be running that long etc until we know what it does..... if it's on the client end (highly unlikely) obviously it shouldn't run that long as otherwise the client wouldn't stick around lol..

      But it sounds like he is running it for processing something on his end, could be processing a lot of data from the database... which could very well then run for 15 minutes.
      It doesn't matter if it is processing millions of database entries.
      It should never run more than a few seconds.
      This is why it is timing out which is a server protection to keep a script from overloading the system.

      Its the same as a PC only allowing a program a set amount of memory.
      If it is allowed to much memory there will not be enough left for the PC to run, and it will lock up or crash. Servers are no different.
      {{ DiscussionBoard.errors[2649310].message }}
  • Profile picture of the author SteveJohnson
    A dataset that takes 15 minutes to process should not be done in PHP. It is comparatively slow compared to other languages like Perl or C##, and not what it was designed for.

    You would be better off to process the data in the background with another program, then view the results on a web page powered by PHP.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2649347].message }}
    • Profile picture of the author ramsarvan
      hi,

      This is not fair to execute a script for 15 minutes, modify your code to break the huge task into smaller task nd process it simultaneously. Changing execution time in .ini file is not the proper solution for it.
      {{ DiscussionBoard.errors[2651404].message }}
  • Profile picture of the author cyphix
    I wouldn't really recommend running multiple copies of the script over the one..... obviously you can run multiple copies to reduce the runtime, but I wouldn't go crazy.

    If you're on a dedicated server, this is going to depend on the amount of cores you have on your system; if you add too many it may run slower over running a smaller amount of longer running scripts because of context switching in the processor between the threads.

    If you run the process in the background you can also set a lower priority to these processes so that other services like apache can still run seamlessly.
    {{ DiscussionBoard.errors[2652137].message }}
  • Profile picture of the author jakeseth12
    A script that runs over 20 seconds needs to be reworked and you should not be attempting to reframe it unless you are a programmer.
    {{ DiscussionBoard.errors[2674194].message }}
  • Profile picture of the author caesargus
    Why does everyone assume just because it takes 15 minutes that it means the script is bad? Sure I've written some bad code that took a long time to update or to process but if that's where you are as a programmer then that's where you are.

    I agree that the program should be reworked and optimized if possible, but if not then keep it how it is and move on. There will be opportunities to fix it later. Depending on how your script is executed will determine how and what you can update.

    Check out the command for ini_set. This allows you to modify settings for your specific script. You cna also run phpinfo() on your page to double heck the settings for that script.
    {{ DiscussionBoard.errors[2741799].message }}
    • Profile picture of the author SteveJohnson
      Originally Posted by caesargus View Post

      Why does everyone assume just because it takes 15 minutes that it means the script is bad? Sure I've written some bad code that took a long time to update or to process but if that's where you are as a programmer then that's where you are.

      I agree that the program should be reworked and optimized if possible, but if not then keep it how it is and move on.
      If the OPer is in a shared hosting environment (or even some VPSs), a 15-minute execution time will earn them a huge hand slap if not outright suspension of the account - not to mention that it probably won't even complete.

      There is no reason for a PHP script to run 15 minutes. NONE. 60 seconds is even pushing it.

      I didn't say it was a bad script (maybe someone else did, I don't know) - what I did say is that this much processing needs to be moved to a Perl/Python (or whatever) script and run in the background, not as a sub process of the web server software.
      Signature

      The 2nd Amendment, 1789 - The Original Homeland Security.

      Gun control means never having to say, "I missed you."

      {{ DiscussionBoard.errors[2741830].message }}

Trending Topics