Forum Moderators: coopster

Message Too Old, No Replies

Running a long PHP script

How to avoid timing out?

         

zulu_dude

9:04 am on May 15, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'm needing to run quite a long PHP script... basically, it's pulling in about 200 URL's and checking that they contain certain information.

Just loading each URL will take a second or two, which is 400 seconds in total, already enough to make PHP time out. One solution to the problem would be to increase the time out value, but that would be a short-term fix. As I need to check more and more URLs, that solution becomes less viable.

All the URLs are stored in a database, so I could check each of them and then set a 'last checked' flag or something similar. The only problem is that I'd like the script to run through all of the entries automatically, without any intervention from me. Would the best way to do this be to have the script check 20 URLs every time it's run and have it called from a cron every 5 minutes? Or is there a more elegant way to get them all to run directly after one another, possibly by using session variables?

Any help/insight would be much appreciated!

jatar_k

3:24 pm on May 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't think you will find a way, especially if there are going to be more and more, to make them all check at once.

I would go the route you mentioned

use a cron
have a last_checked or something similar
select a manageable number of urls - 20 sounds good, 50 might work too, it depends on how much you are doing
check those and then set the last_checked col

you will just have to figure out how often they need to be checked and then figure out your select logic and timing of the cron

zulu_dude

5:36 pm on May 16, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks jatar, that's what I imagined I might have to do.

I have thought of another way with passing the id of the item to be checked through session variables, but I think it would be like killing an ant with a bulldozer! I'm going to keep it nice and simple...

kvnband

7:53 pm on May 16, 2006 (gmt 0)

10+ Year Member



Another option (that I use) is to simply do a JS redirect after the URL has been checked. Basically reload your page with?id=2,?id=3, etc...works beautifully for me...
kevin