Skip to content

Instantly share code, notes, and snippets.

@scribu
Created August 8, 2013 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribu/6180335 to your computer and use it in GitHub Desktop.
Save scribu/6180335 to your computer and use it in GitHub Desktop.
Proof of concept: read content from STDIN; doesn't block if there's nothing there. Works by assuming that content will be available on STDIN immediately, which might not always be the case.
<?php
$read = array(STDIN);
$write = null;
$except = null;
if ( stream_select($read, $write, $except, 0) > 0 ) {
$content = stream_get_contents($read[0]);
} else {
$content = false;
}
var_dump($content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment