Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set time limit for file_get_contents()? [duplicate]

I use SIMPLE HTML DOM for parsing. Some pages take a very long time when i try to get contents. I need to set limit (for example 10 sec) -> go to the next page. Please without socket!

like image 770
Philipp Klemeshov Avatar asked Dec 04 '25 09:12

Philipp Klemeshov


1 Answers

You can use the HTTP context option

So the code would look like

$options = stream_context_create(array('http'=>
    array(
    'timeout' => 10 //10 seconds
    )
));
echo file_get_contents('http://example.com/', false, $options);
like image 97
HSR Avatar answered Dec 05 '25 22:12

HSR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!