473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 3303
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Irvin Amoraal | last post by:
Well, I must say that I am new to working with FTP and am having problems despite the good help I have recieved. I have been working with code supplied by Janwillem Borleffs and have been able to...
0
by: Andres Baravalle | last post by:
Hi, I have a problem using a URL fetching algorithm (HTTP 1.0). To download an image, I used to use this algorithm: <?php Header("Content-type: image/gif"); $referer =...
2
by: Atarikid | last post by:
This script works fine on my redhat9 machine. I use it with Winblows PC I get an error. My site is not shown however it is a XML server accessible over simple HTTP post and get. The error is as...
1
by: Michael T. Peterson | last post by:
I'm having trouble understanding why fsockopen() returns null yet the errstring/errno value yields: "The operation completed successfully. (0)" Here's the code (modified from an example found...
2
by: Fred H | last post by:
I'm communicating with a server using UDP, and it can be narrowed down to this: $us = 75000; //Timeout in microseconds. $con = fsockopen("udp://127.0.0.0","23000");...
6
by: murd | last post by:
Hi, I am trying to complete a post using fsockopen but I'm getting the following error: "Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? I am...
8
by: Yoko | last post by:
So I am using php version 4.3.9 and lets say i have a file on the server called tester.php so i am using fsockopen to point to that file but it gives me a error below. $fh =...
1
by: beau.moore | last post by:
Hi all, I need some help, I am trying to access a service that binds to the loopback address on my linux FC8 server. I think PHP functions but I am unable to get any response back from the...
1
by: jeddiki | last post by:
Hi, I am modifying a ipn script for my use and want to fully understand what it is doing. It seems to me that it is trying to do a cUrl and if that fails it uses a fsockopen function. Here are...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.