Voting

: min(two, two)?
(Example: nine)

The Note You're Voting On

tim
16 years ago
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.

<< Back to user notes page

To Top