Page 1 of 1
urgently help needed for PHP timer
Posted: Thu Apr 29, 2010 7:45 pm
by coax
Hi,
I want to make a script which runs for every certain amount second(Interval)
like this:
Code: Select all
<?
$interval=$_GET["interval"];
$i=0
do
{
echo "Loop: $i, Interval : $interval";
sleep($interval);
}
while(1);
?>
Assume that it is running with the interval of 100(100 seconds) ( localhost/myTimer.php?interval=100)
and sometimes later, a user may request this sript with the interval of 200 ( localhost/myTimer.php?interval=200)
If the user call the script with interval=200, still script with interval 100 is running, and I cant halt the script with interval 100,and even some one call the script with interval 300, the script is running with interval=100 and interval=200, and of course interval=300, I dont know why.
Could anyone help with with it?
thank you in advance.
Re: urgently help needed for PHP timer
Posted: Thu Apr 29, 2010 8:58 pm
by requinix
What is this script for?
Re: urgently help needed for PHP timer
Posted: Thu Apr 29, 2010 9:01 pm
by Christopher
Yes, I think you are misunderstanding PHP. PHP runs inside the web server which is always running and is event driven. Whatever you are trying to do ... it is probably the wrong way to solve the problem.
Re: urgently help needed for PHP timer
Posted: Thu Apr 29, 2010 10:12 pm
by coax
tasairis wrote:What is this script for?
The script is for sending data to a gateway using CURL lib.
This loop should be run every 30 seconds ( for instance), and let the admin to change the interval, so default interval of 30 seconds should be overriden by some other values which is defined by the admin
Re: urgently help needed for PHP timer
Posted: Thu Apr 29, 2010 10:15 pm
by coax
Christopher wrote:Yes, I think you are misunderstanding PHP. PHP runs inside the web server which is always running and is event driven. Whatever you are trying to do ... it is probably the wrong way to solve the problem.
I'm trying to send something to gateway.
I want to send it based on an interval which should be changable, and once the inteval is changed, the script should stop looping based on the previous interval and instead run under new interval value.
Re: urgently help needed for PHP timer
Posted: Thu Apr 29, 2010 11:18 pm
by requinix
coax wrote:tasairis wrote:What is this script for?
The script is for sending data to a gateway using CURL lib.
A little more specific than that. What's the purpose of the data?
Also:
- How much data?
- Does it need to be running 24/7 or is it just used periodically?
- What if you restricted the interval to be a multiple of 30 seconds?
Re: urgently help needed for PHP timer
Posted: Thu Apr 29, 2010 11:31 pm
by coax
tasairis wrote:coax wrote:tasairis wrote:What is this script for?
The script is for sending data to a gateway using CURL lib.
A little more specific than that. What's the purpose of the data?
Also:
- How much data?
- Does it need to be running 24/7 or is it just used periodically?
- What if you restricted the interval to be a multiple of 30 seconds?
The gate way is connected to a set of devices each of which has mac address, for each of mac addresses we should send an xml command like this
<schedule><mac>xxx</mac><time>timestamp</time></schedule>
yes the system needs to be up and running 24/7,
and the interva could be anything 20sec,10sec, 100000sec, 43 sec, .....
thanks.
Re: urgently help needed for PHP timer
Posted: Fri Apr 30, 2010 12:32 am
by Christopher
That does not make a lot of sense. But I would build such a thing using a cron job. Have the PHP script called every second and calculate then next timestamp each time it connects to a MAC. So all you have to do is run through the list and see if one or more timestamps match (i.e. <=) then connect to the address and reschedule it by adding the interval to the current timestamp.