Forum Moderators: coopster
I'm not really experienced with using sockets.. so I dont know if its something im doing in the script or of the page itself is causing more problems. cURL isnt an option for me at the moment. *sigh* I've been messing with this for a week almost and cant seem to get it to work right.
<?php$host = 'rs2.example.co.uk';
$service_uri = 'http://rs2.example.co.uk:8052/admin.cgi?pass=pass&mode=viewxml';
# compose HTTP request header
$header = "GET ".$service_uri." HTTP/1.0\r\n";
$header .= "Host: ".$host."\r\n";
$header .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20041013 Firefox/1.0.0\r\n";
$header .= "Connection: Close\r\n";
$fp = fsockopen($host, 8052, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br/>\n";
echo $fp;
} else {
fputs($fp, $header);
$data = fgets($fp, 200);
fclose($fp);
}
if(isset($data)){
echo $data;
}
?>
note: i changed the password in the url... so if you try and pull it up directly, its not gonna work.
[edited by: coopster at 3:13 am (utc) on Nov. 9, 2006]
[edit reason] generalized url TOS [webmasterworld.com] [/edit]
The timeout error is from the script execution. I would start there I guess. Have a look at the set_time_limit [php.net] function and it's associated configuration directives.
$header .= "Connection: Close\r\n";
$header .= "\r\n";
Also, you need to use HTTP/1.1 instead of 1.0.
$header = "GET ".$service_uri." HTTP/1.1\r\n";
However, if the server uses chunked transfer encoding, the data you're reading will be garbled a bit, which is why cURL is much preferred.