You can use file_get_contents()
and define the timeout using a stream context as explained here:Does file_get_contents() have a timeout setting?
Modified code from the answer there:
<?php$ctx=stream_context_create(array('http'=> array('timeout' => 5 // 5 seconds )));echo file_get_contents('http://example.com/',false,$ctx);?>