Seems like "echo" isn't working (yeah, right)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Flanagan

    #1

    Seems like "echo" isn't working (yeah, right)

    Of course "echo" is working, but I've got a case where php doesn't
    seem to be sending out the result of an "echo." I'm probably doing
    something wrong, but I can't see it.

    I've got the following code on IIS 5.0, Win 2000, PHP 4.3.3, in file
    LH_Svc.php:

    <?php
    $resp = "<response>\r\n ";
    $respLen = strlen ($resp);
    header ("Content-Type: text/xml\r\n");
    header ("Content-Length: $respLen\r\n\r\ n");
    echo ($resp);
    exit;
    ?>

    In a separate command window, I run the following php script:
    <?php
    $server = "localhost" ;
    $url = "/earn/LH_Svc.php";
    $port = 80;
    // open socket
    $fp = fsockopen($serv er, $port);
    if (!$fp) {
    echo "Could not open socket";
    }
    else {
    $postData = "<test>";
    $dataLen = strlen ($postData);

    $postHeader = "POST $url HTTP/1.0\r\n";
    $postHeader .= "User-Agent: PHP-MJF Client\r\n";
    $postHeader .= "Content-Type: text/xml\r\n";
    $postHeader .= "Content-Length: $dataLen\n";
    $postHeader .= "\r\n"; // required extra blank line

    echo ($postHeader);
    echo ($postData);
    echo ("\n=========== =========\n");

    fwrite ($fp, $postHeader);
    fwrite ($fp, $postData);

    $getResponse = fread ($fp, 14096);
    fclose ($fp);

    echo "Length of response is " . strlen ($getResponse) . "\r\n";
    echo $getResponse;
    echo "============== =======\n";
    }
    ?>

    Here's what I get printed out on the command window when I run it:

    D:\EarnApps>d:\ php\php-4.3.3-win32\cli\php.e xe post.cli
    POST /earn/LH_Svc.php HTTP/1.0
    User-Agent: PHP-MJF Client
    Content-Type: text/xml
    Content-Length: 6
    <test>
    =============== =====
    Length of response is 152
    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.0
    Date: Wed, 19 Nov 2003 20:39:02 GMT
    X-Powered-By: PHP/4.3.3
    Content-Type: text/xml
    Content-Length: 12
    =============== ======

    The first file is sending the HTTP headers, and should also then send
    the string "<response>\r\n ". However, I never get that string returned
    to the command window. I see the HTTP headers, but not the <response>.
    This works under Apache, running on a Linux box.

    Any ideas?

    Thanks.
  • R. Rajesh Jeba Anbiah

    #2
    Re: Seems like &quot;echo&quot ; isn't working (yeah, right)

    google_mjf@MJFl anagan.com (Michael Flanagan) wrote in message news:<96f13513. 0311191946.4993 b1b0@posting.go ogle.com>...[color=blue]
    > Of course "echo" is working, but I've got a case where php doesn't
    > seem to be sending out the result of an "echo." I'm probably doing
    > something wrong, but I can't see it.
    >
    > I've got the following code on IIS 5.0, Win 2000, PHP 4.3.3, in file
    > LH_Svc.php:
    >
    > <?php
    > $resp = "<response>\r\n ";
    > $respLen = strlen ($resp);
    > header ("Content-Type: text/xml\r\n");[/color]
    ^^^^^

    You don't need to add \r\n

    ---
    "One who mix sports and patriotism is a barbarian"
    Email: rrjanbiah-at-Y!com

    Comment

    • Michael Flanagan

      #3
      Re: Seems like &quot;echo&quot ; isn't working (yeah, right)

      Thanks for the suggestion. I took out the chars you suggested--no
      change. I then added some newline echos after the last header
      call--still no change. BTW, this code works on Apache/Linux.

      ??

      Michael

      ng4rrjanbiah@re diffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<abc4d8b8. 0311192353.5569 2c12@posting.go ogle.com>...[color=blue]
      > google_mjf@MJFl anagan.com (Michael Flanagan) wrote in message news:<96f13513. 0311191946.4993 b1b0@posting.go ogle.com>...[color=green]
      > > Of course "echo" is working, but I've got a case where php doesn't
      > > seem to be sending out the result of an "echo." I'm probably doing
      > > something wrong, but I can't see it.
      > >
      > > I've got the following code on IIS 5.0, Win 2000, PHP 4.3.3, in file
      > > LH_Svc.php:
      > >
      > > <?php
      > > $resp = "<response>\r\n ";
      > > $respLen = strlen ($resp);
      > > header ("Content-Type: text/xml\r\n");[/color]
      > ^^^^^
      >
      > You don't need to add \r\n
      >
      > ---
      > "One who mix sports and patriotism is a barbarian"
      > Email: rrjanbiah-at-Y!com[/color]

      Comment

      • Michael Flanagan

        #4
        Problem solved--Re: Seems like &quot;echo&quot ; isn't working (yeah, right)

        The problem seems to be that I cannot simply get the response with this:

        $getResponse = fread($fp, 1024);

        I should put that in a 'while' loop until I get EOF or no error.

        Michael

        google_mjf@MJFl anagan.com (Michael Flanagan) wrote in message news:<96f13513. 0311200915.53f4 b45c@posting.go ogle.com>...[color=blue]
        > Thanks for the suggestion. I took out the chars you suggested--no
        > change. I then added some newline echos after the last header
        > call--still no change. BTW, this code works on Apache/Linux.
        >
        > ??
        >
        > Michael
        >
        > ng4rrjanbiah@re diffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<abc4d8b8. 0311192353.5569 2c12@posting.go ogle.com>...[color=green]
        > > google_mjf@MJFl anagan.com (Michael Flanagan) wrote in message news:<96f13513. 0311191946.4993 b1b0@posting.go ogle.com>...[color=darkred]
        > > > Of course "echo" is working, but I've got a case where php doesn't
        > > > seem to be sending out the result of an "echo." I'm probably doing
        > > > something wrong, but I can't see it.
        > > >
        > > > I've got the following code on IIS 5.0, Win 2000, PHP 4.3.3, in file
        > > > LH_Svc.php:
        > > >
        > > > <?php
        > > > $resp = "<response>\r\n ";
        > > > $respLen = strlen ($resp);
        > > > header ("Content-Type: text/xml\r\n");[/color]
        > > ^^^^^
        > >
        > > You don't need to add \r\n
        > >
        > > ---
        > > "One who mix sports and patriotism is a barbarian"
        > > Email: rrjanbiah-at-Y!com[/color][/color]

        Comment

        Working...