Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

posix_mkfifo

(PHP 3 >= 3.0.13, PHP 4, PHP 5)

posix_mkfifo --  Create a fifo special file (a named pipe)

Description

bool posix_mkfifo ( string pathname, int mode )

posix_mkfifo() creates a special FIFO file which exists in the file system and acts as a bidirectional communication endpoint for processes.

The second parameter mode has to be given in octal notation (e.g. 0644). The permission of the newly created FIFO also depends on the setting of the current umask(). The permissions of the created file are (mode & ~umask).

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Замечание: Когда опция safe mode включена, PHP проверяет, имеет ли каталог, с которым вы собираетесь работать, такой же UID (владельца), как и выполняемый скрипт.



posix_mknod> <posix_kill
Last updated: Fri, 26 Jan 2007
 
add a note add a note User Contributed Notes
posix_mkfifo
tech at kwur dot com
19-Sep-2007 10:44
This is still not a solution: if I listen to commands on a pipe and output status on a separate pipe, PHP will block on both opens because something else has not already connected to this pipe.  Because I can't do a low-level fcntl() to to set O_NONBLOCK or something like it, this always locks up and is really stupid.  The only way I can get it to work is to spawn seperate subshells with system() and have them cat, or echo respectively and then the pipes work properly...usually?  Its alot of trouble that we can't set the blocking on the open!!
Enric Jaen
16-Aug-2007 09:22
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);
   }
?>
Uther Pendragon
18-May-2007 02:12
Note (quoted from `man 7 pipe` on debian linux):

"On some systems (but not Linux), pipes are bidirectional:  data  can  be  transmitted  in  both directions  between  the pipe ends.  According to POSIX.1-2001, pipes only need to be unidirectional.  Portable applications should avoid reliance on bidirectional pipe semantics."

Linux pipes are NOT bidirectional.

Also, it appears to me that the use of fifo (named) pipes in php is pretty pointless as there appears to be NO way of determining whether opening (let alone reading) from it will block.  stream_select SHOULD be able to accomplish this, unfortunatly you cannot get to this point because even trying to OPEN a pipe for read will block until there is a writer.

I even tried to use popen("cat $name_of_pipe", 'r'), and even it blocked until it was opened for write by another process.

posix_mknod> <posix_kill
Last updated: Fri, 26 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571