By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,061 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,061 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
go********@MJFlanagan.com (Michael Flanagan) wrote in message news:<96**************************@posting.google. com>...
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");

^^^^^

You don't need to add \r\n

---
"One who mix sports and patriotism is a barbarian"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2

P: n/a
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

ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<ab**************************@posting.google. com>...
go********@MJFlanagan.com (Michael Flanagan) wrote in message news:<96**************************@posting.google. com>...
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");

^^^^^

You don't need to add \r\n

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

Jul 17 '05 #3

P: n/a
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

go********@MJFlanagan.com (Michael Flanagan) wrote in message news:<96**************************@posting.google. com>...
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

ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<ab**************************@posting.google. com>...
go********@MJFlanagan.com (Michael Flanagan) wrote in message news:<96**************************@posting.google. com>...
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");

^^^^^

You don't need to add \r\n

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

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.