Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

I need to run a PHP script for a while - how Does PHP Maximum Execution Time Work?

Posted on 2014-07-31
6
459 Views
Last Modified: 2014-08-06
I have a PHP script that I am testing that works as it should and completes in a little under 3 minutes with a certain size data input test file.

When I move to production, the data input file could potentially be 15 times this large (making execution almost 45 minutes for a million records.)

What do I need to consider? I'm not sure why the script is not being interrupted now - in Webmin > PHP Configuration > Resource Limits, my Maximum Execution Time is set to 30 seconds, and the Maximum Input Parsing Time is set at 60 seconds.

Am I considering all PHP Config options involved here?
What should I increase these options to?
What pro's/con's do I need to consider if I do increase these parameters?
0
Comment
Question by:FirstDirect
6 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40233482
PHP max execution time doesn't apply to PHP on the command line, only when running thru a web server.  

http://php.net/manual/en/info.configuration.php#ini.max-execution-time

http://php.net/manual/en/features.commandline.differences.php
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40233961
You can set and reset the time limit at any time.  If you put this into a loop, you may be able to create a long-running job.
http://php.net/manual/en/function.set-time-limit.php

I emphasize may because PHP is not really made for what you're describing, and the server that is running the PHP script may have time limits, too.  What is the application and why does it take so long to run?
0
 
LVL 29

Expert Comment

by:fibo
ID: 40234101
Problem with running a long job is that it might gobble a significant part of the available CPU resources: that's why there are these limits: if a web site or some other process is running on the machine... it might slow down for a long time.

We have some jobs that need lots of cpu cycles: we have chosen that they will run only 5 sec (which is in fact HUGE!), but have put in place some kind of "progress counter" which allow the job to resume later.
With a cron job, we run this every 15 minutes: we are them pretty sure that user experience on our sites in not impacyed heavily.

Usually such jobs are, as in our case, database related: use transactions (so that your data is kept consistant even if the program is interrupted) and update the counter just at the end of the transaction.

That's the idea, now as Ray suggested you should explain what you want to achieve: brute force computing? batch updates of data?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 58

Expert Comment

by:Gary
ID: 40234287
Check you have the right columns indexed and not columns that don't need it
Optimize your sql
What are some samples of your queries?
0
 
LVL 11

Expert Comment

by:Murfur
ID: 40234295
To add to DB's comment, this sounds like a cronjob waiting to happen!

I would create a results table in the database and get the cronjob to post the results of the lengthy query to the results table. That way a site page can simply query the results table in a fraction of the time.

Commonly a cronjob will use wget to call a web page but wget will timeout just as a browser so as Dave has said, you use PHP on the command line. The caveat is that this needs to be run on the same server as the web site so that the php command refers to a local file e.g. this:

* */2 * * * php /www/sitename.com/html/filename.php  >/dev/null

One thing to consider is how often you want to re-run the query to update the results which is probably  driven by how often the source data changes. If it the query takes 45 mins to generate results then a frequency of a few hours may seem appropriate and probably not less than 2. The example above would run every two hours and subject to your server configuration would only "reply" if there are errors to report i.e. cron failed to run the job but there is nothing to stop you making your own reporting service within the php file. For example, at the simple end of things, you only need to echo result statements and these will typically be emailed to the user account who is running the job. Or you can build your own more complex process to use sendmail etc. to deliver a more complexly structured message such as a summary of the query result or formatting the email content so that the company execs get a graph of sales figures etc. The world is, as they say, your oyster. Code away...

Finally, you mention "Webmin > PHP Configuration" so I'm guessing that you are using a GUI front end to administer the server like Webmin or PLESK. If so then look for the cronjob options or "scheduled jobs" in there which will give you an easier method of administering the schedule.
0
 

Author Closing Comment

by:FirstDirect
ID: 40244394
Thanks, Dave.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question