Home > Backend Development > PHP Tutorial > Solution to the timeout of PHP file_get_contents function reading remote data, c function timeout_PHP tutorial

Solution to the timeout of PHP file_get_contents function reading remote data, c function timeout_PHP tutorial

WBOY
Release: 2016-07-13 09:54:01
Original
828 people have browsed it

Solution to the timeout of PHP file_get_contents function reading remote data, c function timeout

When the network condition is relatively poor, the file_get_contents function often fails to read remote data.
The solution is as follows:
Copy code The code is as follows:
/*After setting the timeout and failing to cooperate, try reading multiple times, the effect is much better than before*/
$url = 'http://www.bkjia.com';
             $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/998805.htmlTechArticleSolution to PHP file_get_contents function reading remote data timeout, c function timeout file_get_contents when the network condition is relatively poor Functions often fail to read remote data. Solve...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template