shlumph Posted October 21, 2008 Share Posted October 21, 2008 Hey guys, I'm writing a web related program in PHP, and need to execute a function every 10 (completely arbitrary) minutes. Is there a PHP function that will allow this? Do I need to use threads? Any help as to what to research, or links to code examples would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 Check out cron, which is a Linux utility. Quote Link to comment Share on other sites More sharing options...
shlumph Posted October 22, 2008 Author Share Posted October 22, 2008 I'm using a shared host under GoDaddy, which provides a cron manager, but only allows the following frequency: hourly, daily, weekly, and monthly. I need a loops iteration to take about 4-20 minutes like this: function getData($arrayItem) { //Do Stuff, Return Stuff } $data = array(); for($i=0; $i<200;$i++) { $data[] = getData($urlArray[$i]); //Pause for 4-20 minutes } And the whole loop must finish. So in the end, it's going to take a while for the program to execute. I basically want to slow down the loop. I could check time every iteration, and see if it's been 10 minutes, but I'm afraid I'll blow up my shared hosting server Quote Link to comment Share on other sites More sharing options...
discomatt Posted October 22, 2008 Share Posted October 22, 2008 Get a better host? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 Get a better host? I second that. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 22, 2008 Share Posted October 22, 2008 if you have SSH you should be able to write it in there Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 if you have SSH you should be able to write it in there GoDaddy? SSH? Lol. Don't think so. Quote Link to comment Share on other sites More sharing options...
shlumph Posted October 22, 2008 Author Share Posted October 22, 2008 Ahaha. I'm too cheap for a better host. I'm thinking I'll look at PHP threading, unless anyone offers $$$ or another solution Quote Link to comment Share on other sites More sharing options...
shlumph Posted October 22, 2008 Author Share Posted October 22, 2008 http://us3.php.net/sleep <-- Exactly what I'm looking for Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 22, 2008 Share Posted October 22, 2008 Ahaha. I'm too cheap for a better host. too cheap? http://dreamhost.com Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 22, 2008 Share Posted October 22, 2008 Did you try a "custom" cron job - http://help.godaddy.com/article/3548 Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted October 22, 2008 Share Posted October 22, 2008 sleep() for 20 mins... I don't think thats a good idea. Ahaha. I'm too cheap for a better host. x10hosting.com Quote Link to comment Share on other sites More sharing options...
FForce2195 Posted October 22, 2008 Share Posted October 22, 2008 Hello. It's a silly idea from a 4-week-old PHP beginner. What if you use Javascript with setTimeout("location.href='URL to the PHP file'", 6000000) to repeat the script? Quote Link to comment Share on other sites More sharing options...
stockton Posted October 22, 2008 Share Posted October 22, 2008 You said "I'm writing a web related program in PHP" and if you look at http://www.stockton.co.za/lb you should see something similar & if you are interested I could share the code with you. Quote Link to comment Share on other sites More sharing options...
haku Posted October 22, 2008 Share Posted October 22, 2008 Create a database that holds a time in it. At the top of all scripts, place a check to see if more than 10 minutes has passed since the time saved in the database. If it has, save the current time in the database, then run the scripts that need running every ten minutes. This method won't work in exactly 10 minute intervals though, as the scripts won't be triggered until the next page access AFTER ten minutes has gone by. But if you can deal with that, then it's an easy way of doing this. Quote Link to comment Share on other sites More sharing options...
shlumph Posted October 22, 2008 Author Share Posted October 22, 2008 Did you try a "custom" cron job - http://help.godaddy.com/article/3548 Did you try a "custom" cron job - http://help.godaddy.com/article/3548 This looks like the best solution. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.