Re: [PHP] Run script every 30 seconds



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).
.



Relevant Pages

  • Re: $ARGV[0] breaks the script
    ... thus if the process is running then it exits, ... > the script will not work ... use absolute paths for binaries (ps and grep in this case) ... > Gregory Machin ...
    (perl.beginners)
  • Re: Parsing a text file line-by-line: skipping badly-formed lines?
    ... splits it into several smaller files, ... line contains binary or control characters), and the script just exits ... cause the script to exit. ...
    (comp.lang.perl.misc)
  • Re: Orderly shutdown of running programs when quitting X
    ... >> Is there a way to run a script before X exits, ... > Why not just lock your console instead, ...
    (Debian-User)
  • Re: exit application script
    ... user out of the application if it's been idle for a set amount of time. ... Is there a way to write a script that exits the application if the user ... Perhaps constantly monitoring the CPU usage of the process? ...
    (microsoft.public.scripting.wsh)
  • Re: Background processes from a script
    ... > - interacts with that application and then exits. ... > X-application to be killed when the script exits or if the script is killed ... > I'll use xterm as a sample application (the real one is different but the ... > echo Sleeping for 60 seconds ...
    (comp.unix.shell)