1

I get this error message: get_headers failed to open stream: Connection timeout

Here is the code:

$file_headers = @get_headers('http://www.example.fr');
print_r(get_headers('http://www.example.fr'));

if ( strpos( $file_headers[0], "200" )) {
    echo 'done';
} else {
    echo 'error';
}   
Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45
Ayoub Bsl
  • 159
  • 2
  • 6
  • 14

2 Answers2

1

Set this for 120 sec timeout (default - 60):

ini_set('default_socket_timeout', 120);
Evgeny Ruban
  • 1,357
  • 1
  • 14
  • 20
0

The program was not able to open the stream within the time limit -- a system default value, often 60 seconds. Check to see that the file exists and is readable. Note that you call get_headers a second time (in the print statement), while the file_headers stream is still active.

Prune
  • 76,765
  • 14
  • 60
  • 81
  • i didn't understand clearly can you explain me thank you – Ayoub Bsl Sep 18 '16 at 02:53
  • What do you not understand? – Prune Sep 18 '16 at 02:58
  • this sentence Note that you call get_headers a second time (in the print statement), while the file_headers stream is still active. – Ayoub Bsl Sep 18 '16 at 12:44
  • You invoke **get_headers** once to set up **file_headers** I believe that this opens the stream. In the next statement, the **print_r**, you call **get_headers** again. I believe that the error message is telling you that it couldn't open the file a second time. – Prune Sep 20 '16 at 04:43