管道数据到命令行PHP? [英] piping data into command line php?

查看:71
本文介绍了管道数据到命令行PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Unix管道将数据管道传输到命令行php脚本中?我已经尝试过

It is possible to pipe data using unix pipes into a command-line php script? I've tried

$> data | php script.php

但是预期的data没有出现在$argv中.有办法吗?

But the expected data did not show up in $argv. Is there a way to do this?

推荐答案

据我了解,$argv将显示程序的参数,换句话说:

As I understand it, $argv will show the arguments of the program, in other words:

php script.php arg1 arg2 arg3

但是,如果将数据通过管道传输到PHP,则必须从标准输入中读取数据.我从来没有尝试过,但是我认为是这样的:

But if you pipe data into PHP, you will have to read it from standard input. I've never tried this, but I think it's something like this:

$fp = readfile("php://stdin");
// read $fp as if it were a file

这篇关于管道数据到命令行PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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