Re: [PHP] Run script every 30 seconds

2006-10-31 Thread Ahmad Al-Twaijiry

yes, I think you can call it ,semi-real-time monitoring

because we want the script when it run it should read some records in
database and update other records


On 10/31/06, Ed Lazor [EMAIL PROTECTED] wrote:


On Oct 30, 2006, at 10:26 AM, Ahmad Al-Twaijiry wrote:
 is it possible to link the script to my php interface (the one that
 the users is using it) and if the php interface page will run the
 script (IN background) if it didn't run for the last 30 seconds ? I
 see  this is very hard and almost impossible , what do you think ?

 PS: also I need to make sure no more than 1 process of the script
 is running :)

Hi Ahmad.  Could you describe what your script is doing?  What type
of information are you wanting users to see?  Is this some sort of
status page?  Is it some sort of semi-real-time monitoring?

-Ed





--

Ahmad
http://www.v-tadawul.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-31 Thread Ed Lazor


On Oct 31, 2006, at 2:48 AM, Ahmad Al-Twaijiry wrote:


yes, I think you can call it ,semi-real-time monitoring

because we want the script when it run it should read some records in
database and update other records


That's kind of vague.  I'm not able to give better advice without  
more information, but it does sound like you'll eventually run into  
some bottlenecks as system usage increases ( and fairly quickly if  
you're collecting data every 30 seconds).


-Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Chris Boget

I have a script that I want it to run every 30 seconds, the problem is
that cronjob can run every 1 minute only, do you have any solution ?


Set the script up as a 2 iteration loop with sleep( 30 ) at the end of the 
first iteration.  Or something like that...


thnx,
Chris 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Run script every 30 seconds

2006-10-30 Thread zoticaicpassion
I'd create a PHP service that stays on the background :), ensuring that such
service never goes off from time to time will be the job of the cron job, a
little dirty, but works for me.

HTH

-Original Message-
From: Ahmad Al-Twaijiry [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 31, 2006 1:29 AM
To: PHP
Subject: [PHP] Run script every 30 seconds

Hi everyone,

I have a script that I want it to run every 30 seconds, the problem is
that cronjob can run every 1 minute only, do you have any solution ?

-- 

Ahmad
http://www.v-tadawul.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread James Tu
I've never tried this myself, but how about having the cron job kick  
off a script which will run script A and script B
Script A runs right away, and script B runs after a delay of 30  
seconds ( usleep(30* 100) )?


-James

On Oct 30, 2006, at 12:29 PM, Ahmad Al-Twaijiry wrote:


Hi everyone,

I have a script that I want it to run every 30 seconds, the problem is
that cronjob can run every 1 minute only, do you have any solution ?

--

Ahmad
http://www.v-tadawul.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Dave Hamber
Sorry, slight adjustment, make that $t=time()-31; in the first line so 
that the script runs immediately.



 You could run the script as a daemon. man daemon.

 The sloppy way of running the script every 30 seconds would be to use 
sleep(30), but that would cause the script to run at 30 seconds + 
execution time.


 If you make a loop like this you could get around that:

 $t=time()+31;
 while(true){
 if(time()$t+30){
 $t=time();
 YourMainScriptFunction();
 }
 else usleep(1000); //adjust to how often you want to check
 }

On 30/10/2006 17:29 Ahmad Al-Twaijiry wrote:

Hi everyone,

I have a script that I want it to run every 30 seconds, the problem is
that cronjob can run every 1 minute only, do you have any solution ?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Ahmad Al-Twaijiry

Thank you all

but the problem is that I don't have root access to the server to
create daemon :)

so if I just run the script in background with 30 seconds sleep and
someone reboot the server  (or the script dies for any reason ) I will
lose my process :)

any other ideas ?


is it possible to link the script to my php interface (the one that
the users is using it) and if the php interface page will run the
script (IN background) if it didn't run for the last 30 seconds ? I
see  this is very hard and almost impossible , what do you think ?

PS: also I need to make sure no more than 1 process of the script is running :)


On 10/30/06, Dave Hamber [EMAIL PROTECTED] wrote:

Sorry, slight adjustment, make that $t=time()-31; in the first line so
that the script runs immediately.


  You could run the script as a daemon. man daemon.
 
  The sloppy way of running the script every 30 seconds would be to use
sleep(30), but that would cause the script to run at 30 seconds +
execution time.
 
  If you make a loop like this you could get around that:
 
  $t=time()+31;
  while(true){
  if(time()$t+30){
  $t=time();
  YourMainScriptFunction();
  }
  else usleep(1000); //adjust to how often you want to check
  }

On 30/10/2006 17:29 Ahmad Al-Twaijiry wrote:
 Hi everyone,

 I have a script that I want it to run every 30 seconds, the problem is
 that cronjob can run every 1 minute only, do you have any solution ?





--

Ahmad
http://www.v-tadawul.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Dr. Suhas Pharkute

You can still use Cronjob with 1 min setting and in use 2 processes

1. Run script immediately
2. Sleep for 30 sec and then run the script

you can use exec/shell_exec functions with output redirected to soem file so
that It will run in background.

That way you have one process running at 0 sec and one running at 30 sec
every minute

Suhas

On 10/30/06, Ahmad Al-Twaijiry [EMAIL PROTECTED] wrote:


Thank you all

but the problem is that I don't have root access to the server to
create daemon :)

so if I just run the script in background with 30 seconds sleep and
someone reboot the server  (or the script dies for any reason ) I will
lose my process :)

any other ideas ?


is it possible to link the script to my php interface (the one that
the users is using it) and if the php interface page will run the
script (IN background) if it didn't run for the last 30 seconds ? I
see  this is very hard and almost impossible , what do you think ?

PS: also I need to make sure no more than 1 process of the script is
running :)


On 10/30/06, Dave Hamber [EMAIL PROTECTED] wrote:
 Sorry, slight adjustment, make that $t=time()-31; in the first line so
 that the script runs immediately.


   You could run the script as a daemon. man daemon.
  
   The sloppy way of running the script every 30 seconds would be to use
 sleep(30), but that would cause the script to run at 30 seconds +
 execution time.
  
   If you make a loop like this you could get around that:
  
   $t=time()+31;
   while(true){
   if(time()$t+30){
   $t=time();
   YourMainScriptFunction();
   }
   else usleep(1000); //adjust to how often you want to check
   }

 On 30/10/2006 17:29 Ahmad Al-Twaijiry wrote:
  Hi everyone,
 
  I have a script that I want it to run every 30 seconds, the problem is
  that cronjob can run every 1 minute only, do you have any solution ?
 



--

Ahmad
http://www.v-tadawul.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Dave Hamber

You could run the script as a daemon. man daemon.

The sloppy way of running the script every 30 seconds would be to use 
sleep(30), but that would cause the script to run at 30 seconds + 
execution time.


If you make a loop like this you could get around that:

$t=time()+31;
while(true){
if(time()$t+30){
$t=time();
YourMainScriptFunction();
}
else usleep(1000); //adjust to how often you want to check
}

On 30/10/2006 17:29 Ahmad Al-Twaijiry wrote:

Hi everyone,

I have a script that I want it to run every 30 seconds, the problem is
that cronjob can run every 1 minute only, do you have any solution ?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread John Nichel

Ahmad Al-Twaijiry wrote:

Hi everyone,

I have a script that I want it to run every 30 seconds, the problem is
that cronjob can run every 1 minute only, do you have any solution ?



Use atd.

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Mitch Miller
Or, you could run two scripts every minute ... one that starts 
immediately, and one that sleeps for 30s before starting.


-- Mitch



Dave Hamber wrote:

You could run the script as a daemon. man daemon.

The sloppy way of running the script every 30 seconds would be to use 
sleep(30), but that would cause the script to run at 30 seconds + 
execution time.


If you make a loop like this you could get around that:

$t=time()+31;
while(true){
if(time()$t+30){
$t=time();
YourMainScriptFunction();
}
else usleep(1000); //adjust to how often you want to check
}

On 30/10/2006 17:29 Ahmad Al-Twaijiry wrote:


Hi everyone,

I have a script that I want it to run every 30 seconds, the problem is
that cronjob can run every 1 minute only, do you have any solution ?





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread David Otton
On Mon, 30 Oct 2006 21:26:29 +0300, Ahmad Al-Twaijiry wrote:

The right way to do this, as others have mentioned, is with a
daemon. Having said that...

is it possible to link the script to my php interface (the one that
the users is using it) and if the php interface page will run the
script (IN background) if it didn't run for the last 30 seconds ? I
see  this is very hard and almost impossible , what do you think ?

http://www.webcron.org/

However, an admin on a shared host may (quite rightly) kick you for
wasting shared resources.

A script that has to be run every 30 seconds sounds like it's covering
for a bad design decision to me. Can you tell us more about what
you're trying to accomplish? We might be able to find a more elegant
solution.

PS: also I need to make sure no more than 1 process of the script is running :)

Locking. At its simplest, have your script create a dummy file when it
first runs, and delete it when it exits. If the file already exists,
then you know that a copy of your script is already running, so you
exit. (Include a timeout in case the script dies halfway through - if
the file is more than 5 minutes old, run anyway).

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Richard Lynch
On Mon, October 30, 2006 11:29 am, Ahmad Al-Twaijiry wrote:
 I have a script that I want it to run every 30 seconds, the problem is
 that cronjob can run every 1 minute only, do you have any solution ?

Run a script that never quits with:
http://php.net/usleep

while (true){
  //your script here
  usleep(3); //3?  rtfm.
}

It won't really really be every 30 seconds, because the script itself
takes time, but it's about as close as you are likely to get without a
ton of probably un-needed work...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Run script every 30 seconds

2006-10-30 Thread Ed Lazor


On Oct 30, 2006, at 10:26 AM, Ahmad Al-Twaijiry wrote:

is it possible to link the script to my php interface (the one that
the users is using it) and if the php interface page will run the
script (IN background) if it didn't run for the last 30 seconds ? I
see  this is very hard and almost impossible , what do you think ?

PS: also I need to make sure no more than 1 process of the script  
is running :)


Hi Ahmad.  Could you describe what your script is doing?  What type  
of information are you wanting users to see?  Is this some sort of  
status page?  Is it some sort of semi-real-time monitoring?


-Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php