note 89642 added to function.posix-mkfifo
| From: | tim at osu1 dot php dot net | Date: | Tue, 17 Mar 2009 18:00:06 +0000 |
| Subject: | note 89642 added to function.posix-mkfifo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152057@lists.php.net to get a copy of this message | ||
For non-blocking, fopen'd read access to a "half-connected" pipe (created with
/usr/bin/mkfifo, posix_mkfifo, etc.), I just go ahead and do:
<?php
$fh=fopen($fifo, "r+"); // ensures at least one writer (us) so will be non-blocking
stream_set_blocking($fh, false); // prevent fread / fwrite blocking
?>
The "r+" allows fopen to return immediately regardless of external writer channel. You
then have to use your own conventions to track $fh as a pseudo-read-only resource, since fwrite
would technically be permitted as well. I've successfully used this approach on Linux with PHP
4.3.10 and PHP 5.2.4 with both half-connected (no writer yet) and pre-connected (writer already
waiting) pipes, polling with stream_select as usual.
----
Server IP: 208.69.120.35
Probable Submitter: 74.199.5.198
----
Manual Page -- http://www.php.net/manual/en/function.posix-mkfifo.php
Edit -- https://master.php.net/note/edit/89642
Del: integrated -- https://master.php.net/note/delete/89642/integrated
Del: useless -- https://master.php.net/note/delete/89642/useless
Del: bad code -- https://master.php.net/note/delete/89642/bad+code
Del: spam -- https://master.php.net/note/delete/89642/spam
Del: non-english -- https://master.php.net/note/delete/89642/non-english
Del: in docs -- https://master.php.net/note/delete/89642/in+docs
Del: other reasons-- https://master.php.net/note/delete/89642
Reject -- https://master.php.net/note/reject/89642
Search -- https://master.php.net/manage/user-notes.php