如何在 Linux 上将 proc_open() 与非标准文件描述符一起使用?

发布于 2024-11-25 18:49:50 字数 555 浏览 3 评论 0原文

proc_open() 文档指出它是可以使用标准文件描述符之外的其他文件描述符:

文件描述符编号不限于 0、1 和 2 - 您可以 指定任何有效的文件描述符编号,它将被传递给 子进程。

但你实际上如何去做呢?

您需要对父进程和子进程执行什么操作,例如通过 proc_open 调用使用额外的输入和输出管道?

编辑:

一个相关问题 - 如果启动的进程也是一个 PHP 函数,您可以使用流包装器 php://fd/3 (将 3 替换为 fd 编号),但此功能仅在 PHP 5.3 中可用.6+。 PHP 5.2 有没有办法访问任意 fd?

The proc_open() documentation states that it's possible to use other file descriptors than the standard ones:

The file descriptor numbers are not limited to 0, 1 and 2 - you may
specify any valid file descriptor number and it will be passed to the
child process.

But how do you actually go about doing this?

What do you need to do on the parent and child process to for example use an extra input and output pipe with a proc_open call?

Edit:

A related question - If the launched process was also a PHP function, you can access an arbitrary fd in PHP with the stream wrapper php://fd/3 (replace 3 with the fd number), but this feature is only available in PHP 5.3.6+. Is there any way of accessing an arbitrary fd in PHP 5.2?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文