Re: [PHP] Run script every 30 seconds



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 <ahmadt@xxxxxxxxx> 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 <dgh@xxxxxxxxxxxxx> 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




Relevant Pages

  • Re: Sleep command quitting
    ... It cannot be that the `sleep` command is terminating. ... That script was popular when I started working at SCO Support in 1989. ... it doesn't really hold the settings you specify. ... anything else comes along and makes further changes, the holdopen script ...
    (comp.unix.sco.misc)
  • Re: WScript.dll not working
    ... But, when i call a script indirectly in my application's exe's context, then it doesn't repond further. ... the sleep method is coded into the ... could call the sleep api directly from script. ...
    (microsoft.public.scripting.vbscript)
  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (comp.lang.perl.misc)
  • my script crashes when I try to rename the file!
    ... OK, thanks, but the script does not seem to rename the files. ... You can set the working directory from within your Perl ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (perl.beginners)
  • More on perl like tail
    ... If I write my script based on this code... ... But first about that sleep comment. ... I see 7-8 lines output to the tail -f slpipe command, ...
    (perl.beginners)