-1

Will the following code timeout after 2 seconds IF the url it's calling is hung up by a DDOS attack?

$ctx = stream_context_create(array( 
                                    'http' => array( 
                                        'timeout' => 2,

                                        ) 
                                    ) 
                                ); 


$data = @file_get_contents( $urlPrimary, 0, $ctxPrimary )
SirM
  • 487
  • 6
  • 22
  • 1
    it wont detect a "DDOS" but simple lack of availability –  Feb 27 '15 at 03:08
  • never use `@` to suppress warnings & errors. Handle them properly. If you want to have more control of the request, use cURL . – Raptor Feb 27 '15 at 03:12
  • 1
    Similar question: http://stackoverflow.com/questions/10236166/does-file-get-contents-have-a-timeout-setting – Raptor Feb 27 '15 at 03:14

1 Answers1

0

If the server is unable to provide the full response within the 2 seconds, file_get_contents() will return FALSE.

wimg
  • 347
  • 1
  • 8