PHP作为守护程序/服务 [英] PHP as daemon/service

查看:119
本文介绍了PHP作为守护程序/服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用php(LINUX机器)实现吗?

can i achieve this with php (LINUX machine):

我已经运行了php二进制文件,然后将其与要执行的php脚本文件一起使用。所以基本上就是这样,

i have php binary already running, and then feed it with php script file to be executed. So it's basically something like,

php myscript.php

但是我需要的是 myscript.php 稍后会提供给PHP二进制文件(cli),有人知道如何实现吗?我需要的是(可能类似),向php处理INPUT并从其输出中获取结果。

but what i need is, the myscript.php is given later to php binary (cli), anyone know how to achieve this? what i need is (maybe something like), write something to php process INPUT and take the result from its output.

请提出任何建议,谢谢。

Any suggestion please, thanks.

推荐答案

目前尚不清楚您真正想要实现的目标,设置的背景或问题所在。调用脚本的方式与您已经提到的完全相同。发送输入并读取其输出可用于 管道

It's not very clear what you actually want to achieve, in which setting, or what the problem is. Invoking the script works exactly as you already mentioned. Sending input and reading its output works with pipes.

cat input.txt | php-cli myscript.php | tee write-output-here.txt

然后使用魔术< a href = http://php.net/manual/zh/wrappers.php.php rel = nofollow> php:// stdin php:// stdout 文件名。

And to read input or write output in PHP use the magic php://stdin or php://stdout filenames.

基本上,这就是将脚本注册为inetd处理程序的方式,该脚本将接收网络输入并将其结果作为结果发送回去。

That's basically how you can register a script as inetd handler, where it would receive network input and can send its output as result back.

这篇关于PHP作为守护程序/服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆