在 C# 中使用命名管道进行进程间通信PHP

发布于 2024-09-18 00:31:20 字数 371 浏览 8 评论 0原文

在 C# 中使用命名管道进行进程间通信很容易,但我不确定如何在 php 中执行此操作,或者是否可能。所以我有这些问题:

  1. php 中可以使用命名管道吗?
  2. 是否可以有一个 C# 命名管道客户端连接到 php 命名管道服务器?
  3. 我到底要怎么编码呢? :)

对上述任何问题的回答都会如此有帮助..谢谢:)

编辑:它是一个独立的 php 程序,而不是基于网络的应用程序。

edit2:命名管道服务器可以在C#端,也可以在PHP端,这并不重要。我已经为两者制作了 C# 示例..但我不知道从哪里开始 php

Interprocess Communication using Named Pipes in C# is easy, but im not exactly sure how to do this in php, or if its even possible. so i have these questions:

  1. Is named pipes possible in php?
  2. Is it possible to have a C# named pipe client, connect to a php named pipe server?
  3. how the heck would i code that? :)

an answer to any of the above questions would be so helpful.. thanks :)

edit: Its a stand alone php program, not a web-based app.

edit2: The named pipe server can be in the C# side, or the PHP side, it doesnt matter. I have made C# examples for both.. but i dont know where to start for php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲性难收 2024-09-25 00:31:20

如果它已经创建,那么您可以使用 PHP 的 fopen 函数将命名管道作为文件打开。

在 Windows 中,管道“文件”路径看起来像“\\.\pipe\pipe_name”,但是有一个 开放问题 阻止了此操作。解决方法是使用计算机的名称而不是路径中的点:

$name = php_uname('n');
$pipe = fopen("\\\\" . $strComputername . "\\pipe\\pipe_name", "r+");

虽然我投票支持 Tommy 推荐的套接字,但它们很简单,跨平台,并且如果需要的话还可以跨机器。

If it is already created then you can open a named pipe as a file using PHP's fopen function.

In windows the pipe "file" path looks like "\\.\pipe\pipe_name", however there is an open issue in PHP which prevents this from working. The workaround is to use the computer's name instead of the dot in the path:

$name = php_uname('n');
$pipe = fopen("\\\\" . $strComputername . "\\pipe\\pipe_name", "r+");

Though I vote for sockets like Tommy recommended, they're easy, cross-platform, and inter-machine if need be.

彼岸花似海 2024-09-25 00:31:20

可以使用套接字吗?为什么它必须是管道?

看起来 PHP 有很多套接字:
https://www.php.net/sockets

流函数:
http://php.net/manual/en/ref.stream.php

你看到这个了吗?
PHP 和命名管道: http://my .opera.com/zomg/blog/2007/08/29/php-and-named-pipes

<?php
//Open pipe and write some text to it.
//Mode must be r+ or fopen will get stuck.
$pipe = fopen('testpipe','r+');
fwrite($pipe,'this is some text');
fclose($pipe);
?>

posix_mkfifo:
http://www.phpbuilder.com/manual/function.posix-mkfifo。 php

编辑 我假设你在 Windows (C#) 上,所以这可能不起作用......

Can you use sockets? Why does it have to be a pipe?

Looks like PHP has lots for sockets:
https://www.php.net/sockets

Stream Functions:
http://php.net/manual/en/ref.stream.php

Did you see this?
PHP and named pipes: http://my.opera.com/zomg/blog/2007/08/29/php-and-named-pipes

<?php
//Open pipe and write some text to it.
//Mode must be r+ or fopen will get stuck.
$pipe = fopen('testpipe','r+');
fwrite($pipe,'this is some text');
fclose($pipe);
?>

posix_mkfifo:
http://www.phpbuilder.com/manual/function.posix-mkfifo.php

EDIT I am assuming you are on windows (C#) so that may not work....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文