terminal locks up upon second running of this CLI PHP function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    #1

    terminal locks up upon second running of this CLI PHP function

    [PHP]
    function &getResponse () {

    /*----------------------------------------------------------------------------------------------
    New 7/29/2005: Windows can use STDIN, however, the 'con' input data
    stream, i.e. 'console',
    is built into DOS functionality and produces a better data input
    stream result. Use that
    for Windows. If this stream is not available or if you are using
    UNIX, you will simply
    open using STDIN by default
    -----------------------------------------------------------------------------------------------*/
    if ($_ENV['windir'] || $_SERVER['windir']) $responseID =
    @fopen('con', 'rb');
    echo "111test111 \n";
    if (!$responseID) $responseID = @fopen('php://stdin', 'r') or
    die('Cannot read stdin: ' . STDERR);
    echo "\nresponse ID = $responseID 222test222\n";
    while (($response = @fgets($respons eID, 1024)) !== false) {
    echo "333test333 \n";
    @fclose($respon seID);
    return $response;
    }
    }
    [/PHP]

    This is what you get upon running:


    php -q /home/phillip/docs/mu-spin/image_catalog/install.php
    Is this your first time creating the tables into the database "ivc"?
    (y/n Enter = n)111test111

    responseID = Resource id #22 222test222

    333test333

    1where am I?
    Do you want to repopulate the usernames table (y/n Enter = n)111test111

    responseID = Resource id #25 222test222

    [Just sits there until you hit CTRL-C and break out]
    Environment: PHP 5.0.4 using Fedora Core 4

    The purpose of getResponse() is simply to wait for user response from
    STDIN and return whatever the user sends back.

    Thanx
    Phil

  • comp.lang.php

    #2
    Re: terminal locks up upon second running of this CLI PHP function

    Tried to perfect it, to no avail. Still locks up cold when you're
    trying to input using PHP 4.3.8 - PHP 5.0.4 using Fedora Core 4.

    [PHP]
    function &getResponse () {

    /*----------------------------------------------------------------------------------------------
    New 8/12/2005: If constant STDIN exists, a constant data-input stream
    exists and there is no
    need to open an input stream. Retrieve from there and return. Only
    available in PHP 4.3+
    to PHP 5+ and if STDIN consists of a valid constant input stream
    -----------------------------------------------------------------------------------------------*/
    $version = trim(substr(exe c('php -v'), 3, 8));
    if ((preg_match('/^4\.[3-9]/', $version) || preg_match('/^5\.[0-9]/',
    $version)) && STDIN) {
    $response = trim(@fgets(STD IN, 256));
    return $response;
    }


    /*----------------------------------------------------------------------------------------------
    New 7/29/2005: Windows can use STDIN, however, the 'con' input data
    stream, i.e. 'console',
    is built into DOS functionality and produces a better data input
    stream result. Use that
    for Windows. If this stream is not available or if you are using
    UNIX, you will simply
    open using STDIN by default
    -----------------------------------------------------------------------------------------------*/
    if ($_ENV['windir'] || $_SERVER['windir']) $responseID = @fopen('con',
    'rb');
    if (!$responseID) $responseID = @fopen('php://stdin', 'r') or
    die('Cannot read stdin: ' . STDERR);
    if ($responseID) {
    while (($response = @fgets($respons eID, 1024)) !== false) {
    @fclose($respon seID);
    return $response;
    }
    return "\n"; // DEFAULT SINCE NOTHING COULD BE OBTAINED
    }
    return "\n"; // DEFAULT SINCE NOTHING COULD BE OBTAINED
    }
    [/PHP]

    Phil

    Comment

    • comp.lang.php

      #3
      Re: terminal locks up upon second running of this CLI PHP function

      GOT IT! Apparently there is a "feature" in older PHP versions than
      4.3.3 that can't interpret STDIN, whereas certain newer versions of PHP
      (4.3.11 - 5.0+) can't interpret (php://stdin) either!

      Phil

      Comment

      Working...