Skip to content

Instantly share code, notes, and snippets.

@JakubOnderka
Created September 16, 2014 12:04
Show Gist options
  • Save JakubOnderka/fcbbba47aa4b1a650fa6 to your computer and use it in GitHub Desktop.
Save JakubOnderka/fcbbba47aa4b1a650fa6 to your computer and use it in GitHub Desktop.
<?php
function nonBlockingReadLineFromStdIn()
{
$read = array(STDIN);
$write = array();
$except = array();
var_dump('Before stream select.');
$result = stream_select($read, $write, $except, 0);
var_dump('After stream select.', $result);
if ($result === false) {
throw new RunTimeException("Can not select stream STDIN");
}
if ($result === 0) {
return false;
}
var_dump('Before get line.');
$getLine = stream_get_line(STDIN, 1);
var_dump('After get line.', $getLine);
return $getLine;
}
function getPathsFromStdIn()
{
$content = '';
while (($line = nonBlockingReadLineFromStdIn()) !== false) {
$content .= $line;
}
var_dump('Content', $content);
if (empty($content)) {
return array();
}
$lines = explode("\n", rtrim($content));
return array_map('rtrim', $lines);
}
getPathsFromStdIn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment