Put data in php://input from command line

一曲冷凌霜 提交于 2019-12-10 15:12:48

问题


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.

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

The script could be summarized in this:

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

回答1:


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

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'); ?>

or

<?php echo stream_get_contents(STDIN); ?>


来源:https://stackoverflow.com/questions/34455941/put-data-in-php-input-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!