简体   繁体   English

Windows / Mac / Linux上的php中的命名管道?

[英]Named pipe in php on Windows/Mac/Linux?

I'm currently using proc_open() in php to communicate with command line tools. 我目前在php中使用proc_open()与命令行工具进行通信。 It automatically creates up to 3 file descriptors for STDIN, STDOUT and STDERR because more than 3 pipes breaks Windows compatibility. 它会自动为STDIN,STDOUT和STDERR创建最多3个文件描述符,因为3个以上的管道破坏了Windows的兼容性。 It works great on Windows XP and 10.7 on my Mac. 它在Windows XP和Mac上的10.7上都很好用。

However, I would like to be able to create my own named pipes for better control. 但是,我希望能够创建自己的命名管道以实现更好的控制。 If I'm unable to do so, then I have to maintain references between the process resource and its stream resources, which is overly complicating my code. 如果无法执行此操作,则必须维护流程资源及其流资源之间的引用,这会使我的代码过于复杂。 I can't use files because they fill up disk space for long tasks. 我无法使用文件,因为它们会填满磁盘空间以执行长任务。 I'm also trying to avoid using sockets because they aren't enabled by default in php. 我也试图避免使用套接字,因为在php中默认情况下未启用它们。

Here are the links I have found so far: 这是我到目前为止找到的链接:

http://bytes.com/topic/php/answers/557245-named-pipes-windows http://bytes.com/topic/php/answers/557245-named-pipes-windows

https://bugs.php.net/bug.php?id=29005 https://bugs.php.net/bug.php?id=29005

Interprocess Communication using Named Pipes in C# + PHP 在C#+ PHP中使用命名管道进行进程间通信

http://en.wikipedia.org/wiki/Named_pipe#In_Windows http://en.wikipedia.org/wiki/Named_pipe#In_Windows

http://www.phpkode.com/source/p/xp-framework/xp-framework-xp-framework-554d8b2/core/src/main/php/rdbms/mysqlx/NamedPipe.class.php http://www.phpkode.com/source/p/xp-framework/xp-framework-xp-framework-554d8b2/core/src/main/php/rdbms/mysqlx/NamedPipe.class.php

I've tried each of these in php 5.3.13 but none of them work: 我已经尝试了php 5.3.13中的每一个,但是它们都不起作用:

var_dump(fopen("\\\\.\\pipe\\mypipe", "w+"));
var_dump(fopen("\\\\127.0.0.1\\pipe\\mypipe", "w+"));
var_dump(fopen("\\\\".php_uname('n')."\\pipe\\mypipe", "w+"));

I always get an error that looks like this: 我总是收到如下错误:

PHP Warning:  fopen(\\.\pipe\mypipe): failed to open stream: No such file or directory in C:\Documents and Settings\Administrator\Desktop\named-pipe.php on line 15
PHP Stack trace:
PHP   1. {main}() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:0
PHP   2. fopen() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:15

Warning: fopen(\\.\pipe\mypipe): failed to open stream: No such file or directory in C:\Documents and Settings\Administrator\Desktop\named-pipe.php on line 15

Call Stack:
    0.0018     431936   1. {main}() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:0
    0.0018     432072   2. fopen() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:15

bool(false)

So my question is, has anyone successfully opened a named pipe on Windows XP? 所以我的问题是,有没有人在Windows XP上成功打开过命名管道? If not, what versions of Windows support named pipes? 如果没有,什么版本的Windows支持命名管道? I don't know if the pipe "file" descriptor needs to already exist, for example if it has to be created by mysql or other services. 我不知道管道“文件”描述符是否需要已经存在,例如是否必须由mysql或其他服务创建。

Bonus points if you can supply cross-platform code, perhaps using posix_mkfifo() or system("mkfifo pipe") like in this answer: 如果您可以提供跨平台代码,则可以加分,例如可以使用posix_mkfifo()或system(“ mkfifo pipe”),如下所示:

http://www.php.net/manual/en/function.popen.php#22801 http://www.php.net/manual/zh/function.popen.php#22801

Ideally the solution should work with a vanilla install of php, so without sockets, etc, but anything helps thanks. 理想情况下,该解决方案应与php的原始安装一起使用,因此无需套接字等,但是任何帮助都可以。

Have you realy read http://bytes.com/topic/php/answers/557245-named-pipes-windows ? 您确实阅读过http://bytes.com/topic/php/answers/557245-named-pipes-windows吗?

The solution is not to use dots in pipe's name. 解决方案是不要在管道名称中使用点。

All your samples are with dots in pipe's name. 您的所有样本在管道名称中均带有点。

Is this server code you are writing? 您正在编写此服务器代码吗? It looks like you're using the client side calls perhaps you need to create the pipe first? 看来您正在使用客户端调用,也许您需要首先创建管道?

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365590(v=vs.85).aspx https://msdn.microsoft.com/zh-CN/library/windows/desktop/aa365590(v=vs.85).aspx

Not sure you can write the server in php, needs CreateNamedPipe(). 不知道您可以用php写服务器,需要CreateNamedPipe()。

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

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