Created
November 23, 2011 00:36
-
-
Save sabarasaba/1387550 to your computer and use it in GitHub Desktop.
Setting a timeout for the file_get_contents function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Create the stream context | |
$context = stream_context_create(array( | |
'http' => array( | |
'timeout' => 3 // Timeout in seconds | |
) | |
)); | |
// Fetch the URL's contents | |
$contents = file_get_contents('http://reddit.com', 0, $context); | |
// Check for empties | |
if (!empty($contents)) | |
{ | |
// Woohoo | |
echo $contents; | |
} | |
else | |
{ | |
// DANG ! | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you ,it's very helpful .