472,127 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

problem with fsockopen & fgets

I'm stuck on a problem with getting data from a XML data stream. This
stream is large and trying to use fsockopen to get the stream down.

I've tetsed the code by telneting into the machine/port but I am
getting some of the data but not all. I don't know the stream size.

Code snippit below:

function txrx($server, $port, $tx){
$rx = "";
if ($server == "") {
$rx = "Error - Missing Server";
}
if ($port == "") {
$rx = "Error - Missing Port";
}
$fp = fsockopen($server, $port);
if($fp) {
fputs($fp, $tx);
$rx .= fread($fp, 2048);
fclose($fp);
}
return $rx;

}
Any suggestions ?

Can you please post to the group and send me an e-mail at
34*****@gmail.com

Thanks
Colin Bell
Jul 17 '05 #1
2 3238
Colin Bell wrote:
I'm stuck on a problem with getting data from a XML data stream. This
stream is large and trying to use fsockopen to get the stream down.

I've tetsed the code by telneting into the machine/port but I am
getting some of the data but not all. I don't know the stream size.

Code snippit below:

function txrx($server, $port, $tx){
$rx = "";
if ($server == "") {
$rx = "Error - Missing Server";
}
if ($port == "") {
$rx = "Error - Missing Port";
}
$fp = fsockopen($server, $port);
if($fp) {
fputs($fp, $tx);
$rx .= fread($fp, 2048);
fclose($fp);
}
return $rx;

}
Any suggestions ?
Yes. you are only reading the first 2048 bytes. Look at this example FROM THE
DOCS and compare it to yours... the problem should be obvious...

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>

Can you please post to the group and send me an e-mail at
34*****@gmail.com

Thanks
Colin Bell

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #2
Hello,

On 08/20/2004 11:32 AM, Colin Bell wrote:
I'm stuck on a problem with getting data from a XML data stream. This
stream is large and trying to use fsockopen to get the stream down.

I've tetsed the code by telneting into the machine/port but I am
getting some of the data but not all. I don't know the stream size.


If this is being sent to an HTTP server, you need to follow the HTTP
protocol. In that case you may want to try this HTTP client class that
provides a way to send files either by emulating POST form uploading or
just by submiting the XML file in the request body.

http://www.phpclasses.org/httpclient
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Irvin Amoraal | last post: by
reply views Thread by Andres Baravalle | last post: by
2 posts views Thread by Atarikid | last post: by
1 post views Thread by Michael T. Peterson | last post: by
6 posts views Thread by murd | last post: by
8 posts views Thread by Yoko | last post: by
1 post views Thread by beau.moore | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.