I’ve made this PHP file that could potentially take days to complete.
Initial tests show it stops working after some time.
I would like to know what the time limit is for PHP scripts on the server.
Plus, Does anybody know a why to up the limit? It doesn’t necessary have to be a straight forward config update.
check this out for more info:
But why on earth do you have a script that takes days to complete? Maybe there is a better way if you explain what you are trying to do…
Well, My client struck a deal with a massive website and is allowed to be a re distributor of all their data. At first the XML feed was too big to process, so I got them to separate them into countries. Now I was able to get my script to do one feed at a time to reduce the times.
Lets take the USA feed alone for example, there are over 60,000 items, and PHP could import them at about 6,000/hour. But then…
We needed to create local tumbnails for the images that come along with the feed. That takes a HELL OF ALOT longer, ALOT LONGER. like from 6,000/hour to about 600/hour.
So PHP times out and it’s frustrating because the alternative is to do all this processing on my laptop and then FTP the thumbnails up, but this will place my laptop out of action for who knows how long.
I’ve looked at set_time_limit() before and got no where, but I did see this this time round:
I am ‘includes’ function files and using a MySQL database so that probably messes with it, but I’m not sure how to resolve it.
Mhh i haven’t handled such large xml files before..
Maybe the way to do it is in chunks of (x)amount.
Then keep track of where you are in the xml file in a database.
You make a cronjob which calls the php file every 5 minutes to do (x)amount of lines and then save on what line it stops so the next cronjob can start there. You will have to find out how many lines can be done in 5 minutes by the script to fill in the (x)amount.
I am not sure how to do this, ti am just thinking out loud and maybe it helps you.
It’s probably a smart idea to find a forum dedicated to php for this, because its a though question.
I agree that the way in which you are going about this is not the most efficient approach.
Firstly, 6000 transactions/hour = 100 transactions/min = 1.66 transactions/sec = a very slow script! It’s possible that it’s just necessarily slow, that PHP isn’t the optimal scripting language or that it’s just running on an overloaded web server.
This brings me to my first point – don’t run the script through a website, which can timeout, etc. The webserver will limit the amount of available ram and other resources the script can use. Instead, run the script directly from the commandline using php myscript.php. This will be much more efficient although if it will still be difficult to manage if it’s going to take several days.
If this is quite a processor/memory intensive operation (and it sounds like it is) consider using Amazon EC2. With Amazon EC2 you can get a virtual private server up and running in minutes, and you are only charged by the hour for use. It’s really cheap (and you can of course pass any costs on to your client).
Something else worth looking into would be Amazon Simple Queue Service. It’s designed for this sort of scenario where you have a lot of processing to do in batch. It’s sort of a similar idea to breaking into chunks and using the cron, only more reliable.
Firstly, you will need to create your queue:
Then in the processing servers:
The benefit of this strategy is that you can have as many processing servers reading the queue as you like. So if you think it’s going to take 72 hours on one server just create 7 servers and it should be all done in under 2 hours.
You must be logged in to reply to this topic.
*May or may not contain any actual "CSS" or "Tricks".