Page 1 of 1
fread();
Posted: Tue Dec 06, 2005 6:38 am
by scts102
I am using the fread function to get data from a remote server. The problem is, however, that I do not know the length of data being recieved.
How can I get the data from the remote server without knowing the length of the data?
Posted: Tue Dec 06, 2005 7:42 am
by Chris Corbyn
file_get_contents() -- Much simpler, one-step, no length needed

Posted: Tue Dec 06, 2005 8:34 am
by m3mn0n
Indeed.
Also, check out
http://www.php.net/filesystem for more functions that relate to working with files. There is also many user comments there that are helpful.
Posted: Tue Dec 06, 2005 5:02 pm
by scts102
Could you please give me an example of how to use that?
I tried it, but I got an error, something along the lines of expecting string resource.
here is what I tried:
Code: Select all
$fp = @fsockopen("tcp://".server($addr), $port, $errno, $errstr);
$tmp= hlsend($fp, "\\version\\");
$c = '';
$c .= file_get_contents($tmp);
//echo("Version:=");
echo($c);
I also tried the file_get_contents with $fp instead of $tmp....I am inexperienced with this sort of thing...
Posted: Tue Dec 06, 2005 5:14 pm
by John Cartwright
Firstly, is there a specific requirement of using sockets to get the data instead of only file_get_contents?
File_get_contents does not need filepoints, so does not need fsockopen().
Also whats that hlsend()?
Posted: Tue Dec 06, 2005 5:40 pm
by scts102
Sorry, I should have explained better:
This is an extansion off of another topic (See: Query Server in PHP-Code)
Basically, a connection is opened to a server, and a command is sent to it. I need to get the server's response, and display it (A "query", if you will). the response will always be a simple string:no array of values. However, I dont know the length of the data being sent from the server, so using fRead would be difficult (for me anyway...maybe there is a workaround?)
hlsend is a function :
Code: Select all
function hlsend ($udp, $str) {
fwrite($udp, "${str}");
fread($udp, 1);
}
Posted: Wed Dec 07, 2005 2:36 am
by Chris Corbyn
file_get_contents prob wont work on that then.
Try strlen() to get the length, or find the documentation for whatever protocol you're using
