A way to have a non-blocking pipe reader is to check first if the pipe exists. If so, then read from the pipe, otherwise do other stuff. This will work assuming that the writer creates the pipe, writes on it, and after that deletes the pipe.
This is a blocking writer:
<?php
$pipe="/tmp/pipe";
$mode=0600;
if(!file_exists($pipe)) {
umask(0);
posix_mkfifo($pipe,$mode);
}
$f = fopen($pipe,"w");
fwrite($f,"hello"); unlink($pipe); ?>
And this is the non-blocking reader:
<?php
$pipe="/tmp/pipe";
if(!file_exists($pipe)) {
echo "I am not blocked!";
}
else {
$f = fopen($pipe,"r");
echo fread($f,10);
}
?>