如何在 PHP 中将守护进程变成流
我有一个守护进程(用 C 语言编写,但我认为这并不重要),它用 printf 输出消息,并且可以获取输入并用此输入执行操作(同样,这并不重要,但他将这些消息发送到不同的机保存在数据库中)。
我的问题是,如何使这个守护进程成为 PHP 中的流,以便我可以挂钩输入/输出,例如 file_put_contents 到此流。
I have a daemon (written in C, but I assume it does not really matter) which outputs messages with printf, and can get input and do stuff with this input (again, not really important what, but he sends those messages to a different machine to be saved there in the DB).
My question, how can I make this daemon to be a stream in PHP, so I can hook the input/output of, for example, file_put_contents to this stream.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果这是您要执行的命令,请查看:
http://us.php.net/manual/en/function。 proc-open.php
如果它是一个正在侦听特定端口(TCP 通信)的进程,您可以使用:
http://us.php.net/manual/en/ref.sockets。 :
如果您只是想将其视为具有所有内置文件系统函数/类(yourname://resource/resource.name)的文件,请查看
http://us.php.net/manual/en/class.streamwrapper。 php
和
http://us.php.net/manual/en/ function.stream-wrapper-register.php
Well, if it's a command that you want to execute, check out:
http://us.php.net/manual/en/function.proc-open.php
If it's a process that's listening on a specific port (TCP communication), you can use:
http://us.php.net/manual/en/ref.sockets.php
If you just want to be able to treat it like a file with all the built-in filesystem functions/classes (yourname://resource/resource.name), check out:
http://us.php.net/manual/en/class.streamwrapper.php
and
http://us.php.net/manual/en/function.stream-wrapper-register.php