note 77137 added to function.posix-mkfifo
| From: | EnricJaen at osu1 dot php dot net | Date: | Thu, 16 Aug 2007 16:22:18 +0000 |
| Subject: | note 77137 added to function.posix-mkfifo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129536@lists.php.net to get a copy of this message | ||
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)) {
// create the pipe
umask(0);
posix_mkfifo($pipe,$mode);
}
$f = fopen($pipe,"w");
fwrite($f,"hello"); //block until there is a reader
unlink($pipe); //delete pipe
?>
And this is the non-blocking reader:
<?php
$pipe="/tmp/pipe";
if(!file_exists($pipe)) {
echo "I am not blocked!";
}
else {
//block and read from the pipe
$f = fopen($pipe,"r");
echo fread($f,10);
}
?>
----
Server IP: 80.64.47.13
Probable Submitter: 213.73.41.37
----
Manual Page -- http://www.php.net/manual/en/function.posix-mkfifo.php
Edit -- https://master.php.net/note/edit/77137
Del: integrated -- https://master.php.net/note/delete/77137/integrated
Del: useless -- https://master.php.net/note/delete/77137/useless
Del: bad code -- https://master.php.net/note/delete/77137/bad+code
Del: spam -- https://master.php.net/note/delete/77137/spam
Del: non-english -- https://master.php.net/note/delete/77137/non-english
Del: in docs -- https://master.php.net/note/delete/77137/in+docs
Del: other reasons-- https://master.php.net/note/delete/77137
Reject -- https://master.php.net/note/reject/77137
Search -- https://master.php.net/manage/user-notes.php