我有一个小的PHP脚本,它从php://input
读取数据。我可以在命令行中运行该脚本,但我不知道如何“填充”php://input
。
我尝试使用php file.php < my_test_data
,但它填充了php://stdin
而不是php://input
这个脚本可以概括为:
<?php echo file_get_contents('php://input'); ?>
我有一个小的PHP脚本,它从php://input
读取数据。我可以在命令行中运行该脚本,但我不知道如何“填充”php://input
。
我尝试使用php file.php < my_test_data
,但它填充了php://stdin
而不是php://input
这个脚本可以概括为:
<?php echo file_get_contents('php://input'); ?>
php://input
只适用于从 Web 服务器运行的脚本。
当 CLI 脚本需要访问标准输入时,它们使用 php://stdin
,或者已经打开的流 STDIN
:
<?php echo file_get_contents('php://stdin'); ?>
或者
<?php echo stream_get_contents(STDIN); ?>
php://input
从$_POST
请求中获取数据(你无法在命令行中填充它 - 除非你使用类似于wget
或curl
的工具进行真实请求)。 - raina77ow