Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/156754-replicating-cron-job-in-php/
Share on other sites

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...

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

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?

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.