Page 1 of 1

Irregular scheduling job questions

Posted: Sun Mar 20, 2005 6:29 pm
by chinesewhispers
Hi there

Fairly new to php, with an unusual question (?)

I have a task that I want to carry out, at certain intervals. Currently it have cron set to do it every minute/2 minutes a I wish (though I do find it a pain going in to cPanel to edit the cron job every time I want to change it.

What I would like ot do is come up with an alternative.

I have been looking at the possiblility of using the sleep() function where the value in seconds could range anywhere from 10 seconds to 90. I intend to do this until the number of executions of the task reaches a certain number (50 or 100 ish).

Now, couple of questions. I am currently testing this function by sending an email as my task to execute, and running it from a browser. For testing purposes, I set the sleep (2) and use a for loop to run until executions is equal to 5. This works, I get five emails.

If I increase the value of sleep () to (60), the browser times out (as I would expect) and I only get 1 email. How can I run this script so it contiunues to run on the server? (Is this possible?) Can I start this script from another page in a browser window so that it will continue to run until count reaches its target?

Will this have any effect on CPU usage, I read that sleep passes CPU to other processes, will this be OK on server load?

I know this may not be clear, but I'm new to this, and playing with things I may not understand too much and may be hoping for too much from.

Hopefully it will prove an interesting outcome, but who knows.

Oh, and the reason to use sleep is to enable the frequency of the execution to be modified without affecting the cron, and to allow more flexibility than cron.

Many thanks in advance.

Posted: Sun Mar 20, 2005 6:33 pm
by feyd
you got only 1 email because the script timed out. sleep does not affect time-lapse restrictions. You can use set_time_limit() (if your host allows it) to alter the time-lapse restriction.

Posted: Sun Mar 20, 2005 6:39 pm
by chinesewhispers
OK, I should start from scratch.

Is it possible to do what I am trying to do? Is it possible to have a task repeat every 30 seconds up to 100 times?

Posted: Sun Mar 20, 2005 6:43 pm
by feyd
use a database, or some other "locking" mechanism that you can easily tell when the process is still running, or finished, or no more data is available.

Posted: Mon Mar 21, 2005 12:50 am
by AGISB
I think this will do.

Use a crontab of 1 minute on a script. This script will just check if the time for the execution of the other srcipt is up and calls it if necessary.
This check can be a db or file driven var or any other means to determine if the script needs executing and how many times it should execute.

The problem is that cron is just minutewise. To do it in seconds you would probably have to program a demon that runs indefinately.

Posted: Mon Mar 21, 2005 7:14 am
by Maugrim_The_Reaper
If a browser timeout is in effect - have you looked at the PHP command line?