Forum Moderators: coopster

Message Too Old, No Replies

using php://stdin

         

httpwebwitch

2:57 pm on Feb 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a script that's already finished & QA'd & on the prod servers. I don't want to change it. But I do want to test it locally with some benchmarking stuff.

This script does not run in "web space". it doesn't use $_GET or $_POST or anything arriving from HTTP. This is a script that handles certain internal processes on the server.

Where in a typical web app I'd do this:


$source = $_POST['source'];


This script does this:


// read from stdin
$fd = fopen("php://stdin", "r");
$source = "";
while (!feof($fd)) {
$source .= fread($fd, 1024);
}
fclose($fd);




So now my question is: how do I trigger this script, and pass it input? I'd like to write a separate unit test that sends input to this script and then shows me the output.

Maybe I can go to the Linux CLI and do "> php process.php", but then how does the "stdin" get in there?

coopster

7:30 pm on Feb 24, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Pipe/redirection. Or you can use the argc/argv command line variables.
[php.net...]

httpwebwitch

9:43 pm on Feb 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks coopster

I can see this is not going to be easy, at all. The script is being piped by something equally complex.

I'll find another way to test this beast

coopster

10:02 pm on Feb 24, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Can you send your output from the complex statement to a temporary text file and open that from within your script? Or are you saying the output from your php script is being used as input for the complex statement/process? Either way, could you use temporary text files as alternative input/output mechanisms?