At times the get_file_contents takes too long and that hangs the entire script. Is there any way of setting a time out limit on get_file_contents, without modifying the maximum execution time of the script?
Its taking long because the file does not exist. I am getting "failed to open stream: HTTP request failed!" error. But it takes forever.
Seems to be possible in PHP > 5.2.1 by creating a context with the timeout option.
Slightly amended example from the manual page:
<?php
$opts = array('http' =>
array(
'method' => 'GET',
'timeout' => 120
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/get.php', false, $context);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With