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?
fread();
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
file_get_contents() -- Much simpler, one-step, no length needed 
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.
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.
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:
I also tried the file_get_contents with $fp instead of $tmp....I am inexperienced with this sort of thing...
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);- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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 :
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);
}- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia