Home  >  Article  >  Backend Development  >  Solution to PHP file_get_contents function reading remote data timeout_PHP tutorial

Solution to PHP file_get_contents function reading remote data timeout_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:53:43883browse

The solution to the timeout of the PHP file_get_contents function reading remote data

This article mainly introduces the solution to the timeout of the PHP file_get_contents function to read remote data. This article directly gives the solution. Code, friends in need can refer to it

When the network condition is relatively poor, the file_get_contents function often fails to read remote data.

The solution is as follows:

The code is as follows:

/*After setting the timeout and failing to cooperate, I tried reading multiple times, and the effect was much better than before*/

 $url = 'http://www.jb51.net';

 $opts = array(

'http'=>array(

'method'=>"GET",

'timeout'=>1, //Set timeout

 )

 );

$context = stream_context_create($opts);

$contents = @file_get_contents($url,false,$context);

 ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1000091.htmlTechArticleSolution to the PHP file_get_contents function reading remote data timeout This article mainly introduces the PHP file_get_contents function reading remote data The solution to timeout, this article directly gives the solution...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn