0
$url=$row1['content_url'];
$file_handle = fopen($url,"r");
$line=fread($file_handle,400);
$line1 = wordwrap($line,400,"</br>" );
fclose($file_handle);

the above give is my code for reading data in the text file... it is working fine in my localhost... But it is not working in serevr.....

Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/content/08/11968108/html/dev/index.php on line 57

Warning: fread() expects parameter 1 to be resource, boolean given in /home/content/08/11968108/html/dev/gopi/index.php on line 58

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/content/08/11968108/html/dev/gopi/index.php on line 60

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
user3124621
  • 1
  • 1
  • 4

2 Answers2

2

Make sure the URL in $url contains a wrapper (like http).

Explanation

fopen("www.domain.com","r");

This will look for a local file named www.domain.com

fopen("http://www.domain.com","r");

This will try to get the external file http://www.domain.com (if allow_url_fopen is enabled)

But your error could also indicate an old cached DNS record. If you can, try to change your name server on the production system (e.g.: 8.8.8.8 for the name server from google).

secelite
  • 1,353
  • 1
  • 11
  • 19
0

If you just need to handle the warnings that are thrown (as I did), you may just do this to turn them into Exceptions that can be handled:

set_error_handler(
  function ($err_severity, $err_msg, $err_file, $err_line, array $err_context) {
    // do not throw an exception if the @-operator is used (suppress)
    if (error_reporting() === 0) return false;

    throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line );
  },
  E_WARNING
);
try {
  $fp = fopen("http://example.com","r");
} catch (Exception $e) {
  echo $e->getMessage();
}
restore_error_handler();

Solution based on this thread/question.

CPHPython
  • 12,379
  • 5
  • 59
  • 71