简体   繁体   中英

Put data in php://input from command line

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM