Blogger Information
Blog 11
fans 0
comment 1
visits 13853
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
file_get_contents 获取内容时间过长,解决办法
Alfred的学习笔记
Original
960 people have browsed it

方法1:

  1. ini_set('default_socket_timeout', 1); //设置一下 默认超时时间
  2. file_get_contents($url);//这样就快了
  3. //请求远程链接,对方的服务器 Connection: keep-alive, 所以 PHP 在接收到数据之后, 维持了一段时间, 一直等到超时, 才返回, 所以在设置默认超时时间的情况下会比较慢

方法2:

  1. //使用CURL 直接获取
  2. protected function _get_picture($url){
  3. $ch = curl_init($url);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5. return curl_exec($ch);
  6. }

Ps:建议使用第二种方法

适用于微信获取二维码图片与海报图片合成时使用

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post