title: PHP readline() when STDIN other than keyboard
body: <p>I'm writing an script that is able to read from stdin and then request for confirmation.</p>
  
  <pre><code>&lt;?php
  $stream = fopen('php://stdin', 'r');
  $input = fgets($stream, 1024);
  $confirmation = readline('Are you sure?');
  if ( $confirmation == 'y' )
      /* Do dangerous stuff */
  </code></pre>
  
  <p>When I run it directly:</p>
  
  <pre><code>$ php script.php
  inputdata
  ^D
  Are you sure?
  </code></pre>
  
  <p>But I'm trying to run it using a file as STDIN. In that case, readline() returns false and no confirmation is prompted.</p>
  
  <pre><code>$ php script.php &lt; data.txt
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$ echo "foobar" | php script.php
  </code></pre>
  
  <p>How can I read both from the STDIN and keyboard when invoking this script in this way?</p>
  
  <p>Thanks.</p>