Search code examples
phpcommand-linestdouttemporary-files

php: Grabbing stdout output data from cli tools?


Is it possible to grab the stdout output data from command line tools in php?

Example:

I want to upload a dynamically server-created mix of audio files to the client. The SOX tool lets me mix the input mp3s and send the result to stdout pipe. Could I grab this mix and instantly upload it, without the need of first saving it as a tempfile?


Solution

  • There is a function called passthru(), it will pass through binary data directly to the client's browser. Just make sure your php script put the correct header before the data is passed down, like the content-type, etc.