Does anyone have experience with timing a the execution of a script?
Basically, I am looking for the PHP-equivalent of Javascript's setTimeout() -function.
PHP's sleep() delays the execution of the ENTIRE code (unless used with flush()) - but I want to cycle a function-call every hour.
Any suggestions?
Cheers
Patrik
timed script-execution?
Moderator: General Moderators
If I'm imaging what you want to do correctly, I just did this a few weeks ago. Try setting up your entire script to be what you want to run every hour. Then set up a cron job to access the page through lynx ("lynx -dump http://www.yourpage.com/"). That way you don't have a never-ending program (if it just ran, executing a function every hour) and if the computer gets rebooted, it will pick up again automatically. Is that what you are looking for? If you need help with cron, I can help with that too.
Yes, that's exactly what I am looking for. I've just read up about cron-jobs (never heard about that before) and while I understand the theory, I am not sure how to actually put it into practice.
The idea is to put the PHP-code in a file (say "test.php") which the server then executes with a cron-job every hour.
Well, that's the theory - so, I would very much appreciate if you could help me with cron.
I do have SSH-access (the hosting company disabled telnet because of abuse) to the domain.
Cheers
Patrik
The idea is to put the PHP-code in a file (say "test.php") which the server then executes with a cron-job every hour.
Well, that's the theory - so, I would very much appreciate if you could help me with cron.
I do have SSH-access (the hosting company disabled telnet because of abuse) to the domain.
Cheers
Patrik
Sorry this reply took so long, I was away from a internet connection for quite a while. Try logging onto your server and typing "crontab -l" to have it list what your current cron file is. It will most likely be empty. You can do "crontab -e" to edit it in vi. The format is "min(0-59) hour(0-23) date(1-31) month(1-12) day(0-6, 0 is Sunday) command". So for instance:
That will execute that page every 15 minutes. The asterisks mean that any time matches. So:
would execute that page at midnight on the first day of each month. You can find out more about how to do that by searching for "crontab man" or something.
The command "lynx -dump http://..." has lynx (a simple text-based web browser, if you haven't heard of it) go open the page and just dump the output onto the console. Since cron is running it the output gets lost. You can save the output by saying:
to save the output to a file (make sure you use an absolute reference and watch write permissions as well). THe problem is that will replace the log of old runs. You can have it just insert the new output onto the end of the file by doing this:
I hope that helps, if you have other questions just ask.
Code: Select all
*/15 * * * * lynx -dump http://www.yourpage.com/here.phpCode: Select all
0 0 1 * * lynx -dump http://www.yourpage.com/here.phpThe command "lynx -dump http://..." has lynx (a simple text-based web browser, if you haven't heard of it) go open the page and just dump the output onto the console. Since cron is running it the output gets lost. You can save the output by saying:
Code: Select all
*/15 * * * * lynx -dump http://www.yourpage.com/here.php > /absolute/directory/log.fileCode: Select all
*/15 * * * * lynx -dump http://www.yourpage.com/here.php >> /absolute/directory/log.file