从命令行将数据放入php:// input [英] Put data in php://input from command line

查看:76
本文介绍了从命令行将数据放入php:// input的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的PHP脚本,它从 php:// input 读取。通过我的命令行,我可以运行脚本,但是我不知道如何填充 php:// input

I have a little PHP script that reads from php://input. With my command line I can run the script but I don't know how to "fill" the php://input.

我尝试使用 php file.php< my_test_data ,但它填充 php:// stdin 而不是 php:// input

I tryed using php file.php < my_test_data but it fills the php://stdin not the php://input

脚本可以总结为:

<?php echo file_get_contents('php://input'); ?>


推荐答案

php:// input 仅适用于从Web服务器运行的脚本。

php://input only works for scripts run from the webserver.

当CLI脚本需要访问标准输入时,它们使用 php: // stdin ,或已打开的流 STDIN

When CLI scripts need to access standard input, they use php://stdin, or the already opened stream STDIN:

<?php echo file_get_contents('php://stdin'); ?>

<?php echo stream_get_contents(STDIN); ?>

这篇关于从命令行将数据放入php:// input的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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