urgently help needed for PHP timer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
coax
Forum Newbie
Posts: 4
Joined: Thu Apr 29, 2010 7:33 pm
Location: Melbourne,vic

urgently help needed for PHP timer

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: urgently help needed for PHP timer

Post by requinix »

What is this script for?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: urgently help needed for PHP timer

Post 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.
(#10850)
coax
Forum Newbie
Posts: 4
Joined: Thu Apr 29, 2010 7:33 pm
Location: Melbourne,vic

Re: urgently help needed for PHP timer

Post 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
coax
Forum Newbie
Posts: 4
Joined: Thu Apr 29, 2010 7:33 pm
Location: Melbourne,vic

Re: urgently help needed for PHP timer

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: urgently help needed for PHP timer

Post 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?
coax
Forum Newbie
Posts: 4
Joined: Thu Apr 29, 2010 7:33 pm
Location: Melbourne,vic

Re: urgently help needed for PHP timer

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: urgently help needed for PHP timer

Post 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.
(#10850)
Post Reply