简体   繁体   English

使用PHP命名管道

[英]Using a php named pipe

SITUATION: 情况:

I have created a named pipe (in php ) with the following code: 我用以下代码创建了一个命名管道(在php中 ):

$pipeFile = "/files/queue";
posix_mkfifo($pipefile,0666);

and now I would like to be able to send and extract data to and from the pipe with php pages (like readpipe.php , and put_in_pipe.php ). 现在,我希望能够使用php页面(例如readpipe.phpput_in_pipe.php )在管道中收发数据。


QUESTION: 题:

What function calls exist that I can use inside php files that can send data to the named pipe, and receive data from the named pipe? 我可以在php文件中使用哪些函数调用,这些函数可以将数据发送到命名管道,并从命名管道接收数据

Important: I already now how to send and receive data to and from the pipe via the terminal: 重要说明:我现在已经知道如何通过终端与管道之间收发数据了:

echo lol > /files/queue
cat /path/to/pipe 

What I dont know is how to do this in a php script. 我不知道如何在php脚本中执行此操作。 If I have a page called readpipe.php , and someone enters it, the page would need to have a function call to get the next message inside the pipe (just like cat ... would do for the terminal), and similarly, a page called put_in_pipe.php would need code that puts a message into the pipe (just like echo lol > ... ). 如果我有一个名为readpipe.php的页面,并且有人输入该页面,则该页面将需要一个函数调用以在管道内获取下一条消息(就像cat ...对于终端一样),并且类似地,名为put_in_pipe.php的页面将需要将消息放入管道的代码(就像echo lol > ... )。

Any and all feedback is very much appreciated! 非常感谢任何反馈!

You can use any of file IO functions available in PHP, eg file_put_content / file_get_content to write to the named pipe and read from it, but I doubt it is what you want. 您可以使用PHP中可用的任何文件IO函数,例如file_put_content / file_get_content写入命名管道并从中读取,但是我怀疑这是您想要的。 Pipes can hardly be used in the multi-page scenario you described. 在您描述的多页方案中很难使用管道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM