Re: [PHP] Run script every 30 seconds



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
.



Relevant Pages

  • Re: How to start a Server prog written in C (using sockets) to start at bootup
    ... I tried to make that program run as a daemon by using fork. ... Lets say my server's name is server. ... Wrote a script called script. ... Tauno Voipio wrote: ...
    (comp.os.linux.setup)
  • Re: Confused about init scripts expectations
    ... I am developing a daemon application to handle datalogger ... I have developed the init script that is ... I attempt to start the daemon using the services configuration GUI ... figure is that the EOF signal is not being received by the program. ...
    (Fedora)
  • Re: [opensuse] BASH: has $COLUMNS gone nuts?
    ... You do realize that lines & columns are dynamic values which at least some terminals and login daemons will continuously adjust right? ... What the above shows is that I dragged the corner of my PuTTY window (which was connected to sshd, not every terminal client nor every server daemon does this) making the window a little larger and without issuing any commands, and no possibility that any bashrc or inclusions got executed, the values changed, because the terminal told the daemon and the daemon told it's child processes. ... Try calling them from within a script: ... Although, I would also actually be perverse and say that since the SCO systems predate most others, including ALL linux, that you could actually make the argument that the dwindling remaining production sco boxes in the world are right and the 90 million linux & freebsd & sun boxes are all wrong. ...
    (SuSE)
  • Re: script "chaining"
    ... If a task (such as a report) would take too long to run while attached to the browser, the current system writes the data to a database file. ... The daemon checks that file every 10 seconds and executes the task, writing the data back to database. ... If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. ...
    (comp.lang.php)
  • Debian PHP jabber client deamon
    ... to prevent PHP stopping the script. ... // disconnect from the Jabber server ... Here's the daemon script for running it in Debian. ... # Gracefully exit if the package has been removed. ...
    (comp.lang.php)