monsterpot Posted May 4, 2009 Share Posted May 4, 2009 I have many "pinger" php files located on may domains also across a few servers. Each pinger file, when opened, will look at a text file of URLS on that domain and ping one of them. That file works fine but I am trying to think of a way to control when each of those files runs, rather than having to browse to each one manually. I also want to randomize, or specify set intervals when each file will run (maybe every 30 minutes for example). I've set up a DB of URLs to each of the pinger files and written a script that will run each file by looping through the database but of course it does this without any delay between URLs. So if there are 100 URLs in the database, it runs them one ofter the other with no delay. I want it to run the first, then pause for 30 minutes (or whatever I set) then run the next one and so on. I thought sleep(30) might do but I can't get it to work - can't see where in the loop it would go (if it would indeed work). Does anyone have any thoughts on a solution? If you need more detail - let me know. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Read the manual - http://us.php.net/sleep Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825614 Share on other sites More sharing options...
monsterpot Posted May 4, 2009 Author Share Posted May 4, 2009 Yes, I have tried sleep() but it didn't work for me it just paused execution of the entire output. I want the output to be staggered Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825711 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 So you want the script to run but you want the output to halt for 30 minutes each? Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825714 Share on other sites More sharing options...
monsterpot Posted May 4, 2009 Author Share Posted May 4, 2009 Yes exactly. I run the script and it gathers the list of urls from the database in an array or whatever. The at a specific interval, the script would get the first url from the array and then process it, pause x seconds, get the second url from the array, process it and so on until the url list was complete, then it would stop. [EDIT] - Hang on, I think I might have done it... Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825720 Share on other sites More sharing options...
monsterpot Posted May 4, 2009 Author Share Posted May 4, 2009 sleep() was actually working, it was the way I was testing it that wasnt working. i was trying to echo something to the screen each interval which doesn't work, but the process I wanted to run does work within each interval as they are processed on the server - so that bit is working now. I just need to work on the rest of the script now Thanks Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825736 Share on other sites More sharing options...
hchsk Posted May 4, 2009 Share Posted May 4, 2009 this doesnt help your problem (which i guess is now solved anyway), but would you mind explaining how you continuously run the scraper without a cronjob? also, how are you using sleep to run continuously? won't that just work once? to simply delay the function x amount of time before execution? Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825743 Share on other sites More sharing options...
monsterpot Posted May 4, 2009 Author Share Posted May 4, 2009 I will need to set up a cron to run the actual master php script. What I couldnt figure out was having intervals within that script to process the urls from the datqbase. So if I set the sleep interval to say, to 3600 and I have 100 urls to process form the database, it will take 100 hours to run through. I will just set a cron to run that script once a week or once every 5 days or so. Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825751 Share on other sites More sharing options...
premiso Posted May 4, 2009 Share Posted May 4, 2009 Why are you not using a cron job? Is your server on a Linux box? You can setup a PHP CLI and Cron Job which can run PHP scripts using the CLI (Command Line Interface). This way you just setup the script to run how you want without sleep and then setup a cron job in linux to run that script via PHP CLI. If on Windows, you can do this with Scheduled Tasks. Quote Link to comment https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/#findComment-825757 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.