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($server, $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.exe 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.