I've got a lots of of information that should be read from mysql, examined and in line with the results separate and saved in new records. five record takes about 20 seconds, however the records vary long and so i can't really estimate how lengthy this program will require, however have calculated the process shouldn't take more time considerably longer than 5 hrs, so Let me run it over evening and feel quite certain after i return to work the following morning this program is performed.

Presuming the code is fail safe (I understand right ) how should setup Apache / PHP /Mysql configurations to ensure that after i execute the script to ensure that I can be certain the program won't break and/or otherwise exhaust ram?

(it's essentially running inside a loop fetching teams of 100 rows until it cannot any longer a loop so, I'm wishing the truth that the variables are now being totally reset at the outset of each iteration could keep the memory usage constant.)

The particular size the database when left is 14mb, therefore the amount of the information isn't excessive

(on the side note, it could be also which i haven't designated the utmost assets towards the server configurations, so perhaps this is exactly why it requires 20 seconds to operate 5 records)

Make certain you've removed any max_execution_time limits by setting this to (limitless) inside your PHP.ini or by calling [cde]. This can make sure that PHP does not steer clear of the script mid-execution.
Whether it all possible, you need to run the script from the CLI to ensure that it's not necessary to be worried about Apache timing your request out (it should not, however it might).
As you are dealing with only 15 Megabytes of information I would not be worried about memory usage (128 Megabytes may be the default in PHP). If you're really worried you are able to remove memory limits in PHP by modifying the [cde] to become whether greater quantity of -1 (infinite memory).

Bear in mind modifying the PHP.ini will affect all scripts which are construed with that installation. I favor to make use of the right ini setting functions towards the top of my scripts to avoid harmful global changes.

On the side note: This does not really seem just like a project for PHP. I am not attempting to discourage your utilization of PHP here, but you will find other languages which are more appropriate for command line usage.

Better build your script exit the execution, after which restart it. Keep point where it left before. This can make sure you don't have memory leaks and script doesn't exhaust memory because of some error in garbage collection,which the execution continues if there's unpredicted failure. An easy spend command could be :


you may make other inspections to make sure proper running.

Let me explain, automatically scripts run using a CLI in PHP, default to getting virtually no time limit, unlike scripts tell you CGI, mod_php etc.

So that as mentioned avoid running this via Apache.

If however you MUST do that, consider breaking it lower. You may make a webpage that may process 5-10 results, appends the dump file, then prints out whether meta refresh, or some JavaScript to reload the page with having a parameter telling it where it's up too, and also to continue until done.

Not suggested though.

contributing to a few of the other good options here you might like to take a look at http://www.electrictoolbox.com/article/php/process-forking/ as well as delivering some demands to dev/null if you do not need these to hand back feedback.

Avoid this utilizing a web interface. Run it in the command line but turn to find out if your code could be optimized, or set break points and get it done in "portions"

To begin with http://php.net/manual/en/function.set-time-limit.php put memory_limit at the outset of the script.

For the memory you need to take proper care of that by unsetting any variables, array, pointers that you don't need on each iteration.

Better run the script in the spend (CLI) or as cronjob.