Page 1 of 1
fsockopen() function for sites running on different ports
Posted: Thu Jun 23, 2005 6:23 am
by srirams
All,
If you look at the code below
fsockopen("cmsweb.gci.db.com",80, $errno, $errstr, 30);
This site runs on port 80 in our internal network.
There are some sites which run on different ports.
How do I modify the code to accomodate that.
I did change 80 to something else and it gave an error.
Please suggest other ways to ping the site.
Thanks
Posted: Thu Jun 23, 2005 7:49 am
by Chris Corbyn
You do just change the 80 to something else. Are you sure the server isn't rejecting the socket connection?
What are you trying to connect to and what is the error?
Posted: Thu Jun 23, 2005 8:16 am
by srirams
This is my code
<?php
$fp = fsockopen("rtn.uk.db.com",9001, $errno, $errstr, 30);
if (!$fp) {
echo "Unable to open\n";
} else {
fwrite($fp, "GET /rtn/rtn HTTP/1.0\r\n\r\n");
stream_set_timeout($fp, 2);
$res = fread($fp, 2000);
$info = stream_get_meta_data($fp);
fclose($fp);
if ($info['timed_out']) {
echo 'Connection timed out!';
} else {
echo $res;
}
}
?>
Error message
HTTP/1.0 403 Forbidden Date: Thu, 23 Jun 2005 13:16:34 GMT Server: WebLogic WebLogic Server 6.1 SP4 11/08/2002 21:50:43 #221641 Content-Length: 1319 Content-Type: text/html Connection: Close
Error 403--Forbidden
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.4 403 Forbidden
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.