Dejan Levec

PHP: file_get_contents timeout

How to set timeout when fetching content from web site with file_get_contents?

<?php
$context = stream_context_create(array(‘http’ => array(‘timeout’ > 1)));
echo file_get_contents(\"http://example.com/\", 0, $context);
?>

It’s a good idea to use it with timeout, because otherwise default timeout from php.ini will be used.

Leave a Reply

Your email address will not be published. Required fields are marked *