php://stdin too long?

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

    php://stdin too long?

    <?
    error_reporting (E_ALL & ~E_NOTICE);
    if (@is_file('func tions.inc.php') )
    require_once('f unctions.inc.ph p');
    $xml = preg_replace('/(>)[\n\r\\s\t]+(<)/', '$1$2',
    @file_get_conte nts('php://stdin'));
    $parser = @xml_parser_cre ate();
    @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
    @xml_parser_fre e($parser);
    for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) {
    foreach ($xmlArray[$i]['attributes'] as $attr =$val) {
    foreach (array(&$attr, &$val) as $field) {
    $field = str_replace('{' , '&#123;', str_replace('}' ,
    '&#125;', $field));
    $tclList .= (preg_match('/[\s\t]+/', $field)) ? '{' .
    $field . '} ' : "$field ";
    }
    }
    }
    echo trim($tclList);
    ?>

    This converts XML that is inputted from stdin (a TCL script will input
    the XML-read contents into the PHP script) into a TCL list.

    However, the PHP script in question dies if stdin is too long. I don't
    exactly know the "maximum length" it could be, if there is one, but I
    do know that this scirpt will work with this:
    php -q /home/ppowell/web/blah.php
    <?xml version="1.0" encoding="utf-8" ?><usa><state id="1" abbrev="AL"
    name="Alabama"> </state></usa>

    But will fail with this:
    php -q /home/ppowell/web/blah.php
    <?xml version="1.0" encoding="utf-8" ?><usa><state id="1" abbrev="AL"
    name="Alabama"> </state><state id="2" abbrev="AK"
    name="Alaska"></state><state id="3" abbrev="AZ"
    name="Arizona"> </state><state id="4" abbrev="AR"
    name="Arkansas" ></state><state id="5" abbrev="CA"
    name="Californi a"></state><state id="6" abbrev="CO"
    name="Colorado" ></state><state id="7" abbrev="CT"
    name="Connectic ut"></state><state id="8" abbrev="DE"
    name="Delaware" ></state><state id="9" abbrev="DC" name="District of
    Columbia"></state></usa>

    [nothing is returned, and verifying: $xml = ">"]

    Is there an actual size limit or is there something else wrong? Feel
    free to play with this script as much as you like.

    Thanx
    Phil

  • Janwillem Borleffs

    #2
    Re: php://stdin too long?

    comp.lang.php wrote:
    However, the PHP script in question dies if stdin is too long. I
    don't exactly know the "maximum length" it could be, if there is one,
    but I do know that this scirpt will work with this:
    >
    Remove the @ signs and see what errors are actual returned.

    JW


    Comment

    • comp.lang.php

      #3
      Re: php://stdin too long?


      Janwillem Borleffs wrote:
      comp.lang.php wrote:
      However, the PHP script in question dies if stdin is too long. I
      don't exactly know the "maximum length" it could be, if there is one,
      but I do know that this scirpt will work with this:
      >
      Remove the @ signs and see what errors are actual returned.
      >
      JW
      No errors, no warnings, no notices

      Phil

      Comment

      • Tim Van Wassenhove

        #4
        Re: php://stdin too long?

        comp.lang.php schreef:
        error_reporting (E_ALL & ~E_NOTICE);
        ini_set('displa y_errors', TRUE);

        Comment

        • comp.lang.php

          #5
          Re: php://stdin too long?


          Tim Van Wassenhove wrote:
          comp.lang.php schreef:
          error_reporting (E_ALL & ~E_NOTICE);
          >
          ini_set('displa y_errors', TRUE);
          Tried that too, no errors, no warnings, no notices

          Comment

          • Janwillem Borleffs

            #6
            Re: php://stdin too long?

            comp.lang.php wrote:
            No errors, no warnings, no notices
            >
            I have tried your code and it works just fine; I have tested it with the
            long XML message in both one line and seperated with new lines.

            What you should do besides removing the @ signes, is increasing the error
            reporting level to E_ALL only:

            error_reporting (E_ALL);

            This will at least throw a notice about an undefined variable (not critical
            but sloppy).

            You can also remove file_get_conten ts with the following to test if there's
            a problem with this function:

            $xml = '';
            $fp = fopen('php://stdin', 'r');
            while (!feof($fp)) $xml .= fgets($fp, 1024);
            fclose($fp);

            Most importantly, however, is that you start with a small file which
            basically only reads the input and prints it. If this works, you can start
            rebuilding the script again in small chunks.


            JW


            Comment

            • comp.lang.php

              #7
              Re: php://stdin too long?


              Janwillem Borleffs wrote:
              comp.lang.php wrote:
              No errors, no warnings, no notices
              >
              I have tried your code and it works just fine; I have tested it with the
              long XML message in both one line and seperated with new lines.
              >
              What you should do besides removing the @ signes, is increasing the error
              reporting level to E_ALL only:
              >
              error_reporting (E_ALL);
              >
              This will at least throw a notice about an undefined variable (not critical
              but sloppy).
              >
              You can also remove file_get_conten ts with the following to test if there's
              a problem with this function:
              >
              $xml = '';
              $fp = fopen('php://stdin', 'r');
              while (!feof($fp)) $xml .= fgets($fp, 1024);
              fclose($fp);
              >
              Most importantly, however, is that you start with a small file which
              basically only reads the input and prints it. If this works, you can start
              rebuilding the script again in small chunks.
              >
              >
              It works with a small file, no errors of any kind reported, it's just
              that when I get to a certain length in my stdin that it locks up,
              again, no errors, no warnings, no notices, absolutely nothing.

              But if you want to try for yourself, be my guest:


              That is the XML file; I tried on my PC here at home and it was so
              volatile my processor crashed each time I tested with it!! However, I
              have a very unstable machine so it should not affect anyone else's in
              the same way.

              Phil
              JW

              Comment

              • Janwillem Borleffs

                #8
                Re: php://stdin too long?

                comp.lang.php wrote:
                It works with a small file, no errors of any kind reported, it's just
                that when I get to a certain length in my stdin that it locks up,
                again, no errors, no warnings, no notices, absolutely nothing.
                >
                But if you want to try for yourself, be my guest:

                >
                Looks like you need to do some re-installation, as the file transformed
                within a second on both my WinXP machine running PHP 5 and a Linux box
                running PHP 4...


                JW


                Comment

                • comp.lang.php

                  #9
                  Re: php://stdin too long?


                  Janwillem Borleffs wrote:
                  comp.lang.php wrote:
                  It works with a small file, no errors of any kind reported, it's just
                  that when I get to a certain length in my stdin that it locks up,
                  again, no errors, no warnings, no notices, absolutely nothing.

                  But if you want to try for yourself, be my guest:
                  >
                  Looks like you need to do some re-installation, as the file transformed
                  within a second on both my WinXP machine running PHP 5 and a Linux box
                  running PHP 4...
                  >
                  >
                  JW
                  I wish I could but it's beyond my power, it's a shared hosting service,
                  sorry :(

                  Thanx though
                  Phil

                  Comment

                  Working...