On Sat, Apr 30, 2011 at 2:54 PM, Reindl Harald <h.rei...@thelounge.net>wrote:

>
> Am 30.04.2011 14:04, schrieb Ferenc Kovacs:
> > Hi.
> >
> > recently I found a nice blogpost about how to properly daemonize a php
> > daemon:
> >
> http://andytson.com/blog/2010/05/daemonising-a-php-cli-script-on-a-posix-system/
> > I've noticed in this article, that you can replace/redirect the
> > STDIN/STDOUT/STDERR from inside of your script, you have to close them,
> and
> > open in the correct order.
> > It works (at least on linux), because the opened files will have the
> 1,2,3
> > FDs, because the OS assign the lowest available FD, which will happen to
> be
> > the required ones
>
> the cleaner way is to do this in a /etc/init.d/service-script
>
>
in what way would a service script help this particular issue?
or you mean like a wrapper script which sets the STDIN STDOUT STERR before
launching the script?
eg:
nohup command < /dev/null > /dev/null 2>&1 &

I find the
command
form much cleaner, but with the currently available tools one cannot use
this, because there is no way to properly daemonize* (you can fork and
posix_setsid but you cannot reopen the stdin, stdout and stderr)
at least without doing a proc_open or exec

* http://www.itp.uzh.ch/~dpotter/howto/daemonize



> we are running a monitoring-service written in php wilh a while(1==1)
> as linux-daemon since years and even config-changes are no problem with
> an internal counter for reloading them every 10 while-runs
>
> sleep(1) is a good idea fpr each run to make sure the daemon eats not too
> much ressources useless
>
>
I agree (except while(true) is shorter, or even for(;;) but thats a little
bit confusing at first :P), but this is irrevelant for this discussion, I
didn't asked help on how to write a daemon app.

Tyrael

Reply via email to