On Sat, 30 Apr 2011 13:04:12 +0100, Ferenc Kovacs <tyr...@gmail.com> wrote:
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.
[...]
So to correctly address this, one would need a way to get the FD for a
given fp and to be able to explicitly set the FD for an fp.
The required C methods for this would be the fileno and dup2.
I've started to look around, that maybe there are existing
functions/extensions to make this work.
I've found that with 5.3.6 one can open arbitrary FDs thanks to Gustavo:
http://bugs.php.net/bug.php?id=53465
this is the equivalent of fdopen, which was requested by Dennis Hotson
http://marc.info/?t=126854891300001&r=1&w=2 and he did implement that
https://github.com/dhotson/fdopen-php (+1 for adding fdopen also, the
stream based solution isn't obvious and easy to spot)
But this doesn't help this problem.
[...]
I would like to know, that why do these methods lacks (just nobody needed
them, or maybe it was a decision to keep out such low level methods from
the core)?
and if someone would make those, what should be the best place to add.
[...]
I actually did consider adding support for an extended form of php://fd
where one would specify the desired file descriptor: php://fd/<orig
fd>/<new fd>. It would call dup2 instead of dup.
However, I got into some trouble on shutdown because this could cause
stdout to be closed ahead of time and then the output subsystem would
cause either a segfault or a memory leak (can't recall). I didn't spend
more than 20 minutes on this as it was not the problem I was trying to
solve, so there's probably an easy solution. If you want to work on this,
extending php://fd would likely be a good place.
--
Gustavo Lopes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php