fsockopen() function for sites running on different ports

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

fsockopen() function for sites running on different ports

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

Post 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.
Post Reply