7

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
  • I don't think it's possible; php://input takes its data from $_POST request (which you won't be able to fill in the command line - unless you do real requests with something like wget or curl). Commented Dec 24, 2015 at 17:14

1 Answer 1

9

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); ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.