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. Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/ 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. Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671341 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671364 Share on other sites More sharing options...
discomatt Posted October 22, 2008 Share Posted October 22, 2008 Get a better host? Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671365 Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 Get a better host? I second that. Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671393 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671395 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. Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671396 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671451 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671456 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671471 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671478 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671493 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? Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671537 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. Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671551 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. Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671556 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 Link to comment https://forums.phpfreaks.com/topic/129493-executing-a-function-every-n-minutes/#findComment-671797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.