Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help in fsockopen()........

Status
Not open for further replies.

perlkeats

Programmer
Jul 12, 2005
19
IN
hi

i have the following error if i run my code:

errors:
Warning: fsockopen(): php_network_getaddresses: gethostbyname failed in D:\Program Files\Apache Group\Apache2\htdocs\socketest.php on line 31

Warning: fsockopen(): unable to connect to in D:\Program Files\Apache Group\Apache2\htdocs\socketest.php on line 31
The operation completed successfully.



code:

<?
$url = '/*$url_file = fopen($url,'rb');
while (!feof($url_file)) {
$chunk = fread($url_file,1024);
echo $chunk;
}*/

$retVal='';
$url_parsed = parse_url($url);
$scheme = $url_parsed["scheme"];
echo $scheme;
$host = $url_parsed["host"];
echo $host;
$port = $url_parsed["port"]?$url_parsed["port"]:"80";
echo $port;
$user = $url_parsed["user"];
echo $user;
$pass = $url_parsed["pass"];
echo $pass;
$path = $url_parsed["path"]?$url_parsed["path"]:"/";
echo $path;
$query = $url_parsed["query"];
echo $query;
$anchor = $url_parsed["fragment"];
echo $anchor;
$userAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";

// attempt to open the socket
if($fp = fsockopen($host, $port, $errno, $errstr, 2)){
echo 'open';
$path .= $query?"?$query":"";
$path .= $anchor?"$anchor":"";

// this is the request we send to the host
$out = "GET $path ".
"HTTP/1.0\r\n".
"Host: $host\r\n".
"Connection: Close\r\n".
"User-Agent: $userAgent\r\n";
if($user)
$out .= "Authorization: Basic ".
base64_encode("$user:$pass")."\r\n";
$out .= "\r\n";

fputs($fp, $out);
while (!feof($fp)) {
$retVal.=fgets($fp, 128);
echo 'reading';
}
fclose($fp);
} else {
echo $errstr;
}
?>



regards
keats
 
Are you sure you want to limit the time to establish a connection to two(2) seconds?
Code:
fsockopen($host, $port, $errno, $errstr, [COLOR=red][b]2[/b][/color])

HAve you tried if the function gethostbyname() resolves the hostname to an IP? If not, there might be a problem with the DNS setup.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top