Warning: fopen(): php_network_getaddresses

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
hm2k
Forum Newbie
Posts: 3
Joined: Fri Jan 21, 2005 4:49 pm

Warning: fopen(): php_network_getaddresses

Post by hm2k »

Code: Select all

$xurl = "http://www.".$domain."/";
	$handle = fopen($xurl, "r");
	$xhtml = '';
	while (!feof($handle)) {
	  $xhtml .= fread($handle, 1024);
	}
	fclose($handle);
When I use this to lookup a domain that does not resolve, I get lots of errors such as:
Warning: fopen(): php_network_getaddresses: gethostbyname failed
Warning: fopen(http://www.superman.co.uk/): failed to open stream: No error
How can I avoid this problem?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use the error control operators.
hm2k
Forum Newbie
Posts: 3
Joined: Fri Jan 21, 2005 4:49 pm

Post by hm2k »

I read http://us2.php.net/operators.errorcontrol however I still don't quite understand how to avoid this.
hm2k
Forum Newbie
Posts: 3
Joined: Fri Jan 21, 2005 4:49 pm

Post by hm2k »

I have slighly modified the script:

Code: Select all

$xurl = "http://www.".$domain."/";
	$handle = @fopen($xurl, "r");
	if (error_reporting() == 0) return;
	$xhtml = '';
	while (!feof($handle)) {
	  $xhtml .= fread($handle, 1024);
	}
	fclose($handle);
However I am still getting errors:
Warning: feof(): supplied argument is not a valid stream resource in ~\x.php on line 49

Warning: fread(): supplied argument is not a valid stream resource in ~\x.php on line 50
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php

	error_reporting(E_ALL);
	ini_set('display_errors','1');

	$domain = 'superman.co.uk';
	$xurl = "http://www.".$domain."/";
	$handle = @fopen($xurl, "r");
	$xhtml = '';
	
	if($handle !== false)
	&#123;
		while (!feof($handle)) &#123;
			$xhtml .= fread($handle, 1024);
		&#125;

		fclose($handle);
	&#125;
	else
	&#123;
		$xhtml = 'failed to open page';
	&#125;
	
	echo $xhtml;

?>

Code: Select all

failed to open page
sure works.. :roll:
Post Reply