$url = 'http://wx.qlogo.cn/mmopen/xu0fLo9waqKSTDO7j0kSO41O5Luq3LB6ozUvY4O7OsXUWNicB49fBs8nGYzoqcwGDARQZHpVuic4JSDngEVjVo10BoiaPd0iciaOb/0';$content = file_get_contents($url);file_put_contents('uploads/a.jpg', $content);
Reply content:
$url = 'http://wx.qlogo.cn/mmopen/xu0fLo9waqKSTDO7j0kSO41O5Luq3LB6ozUvY4O7OsXUWNicB49fBs8nGYzoqcwGDARQZHpVuic4JSDngEVjVo10BoiaPd0iciaOb/0';$content = file_get_contents($url);file_put_contents('uploads/a.jpg', $content);
$url
This line adds the ini_set('default_socket_timeout', 1);
default time-out to be set.
You requested this image, the other side of the server support Connection: keep-alive
, so PHP after receiving data, maintained for a period of time, until the timeout to return, so in the case of setting the default time-out is slower.
You can use the same code (do not use ini_set), get this URL http://sfault-avatar.b0.upaiyun.com/160/666/1606661144-55fe2a534b79f_huge256
, quickly back, because the other side told PHP, after the output of the data received, the connection can be closed.
function curl_file_get_contents($durl){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $durl); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_); curl_setopt($ch, CURLOPT_REFERER,_REFERER_); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $r = curl_exec($ch); curl_close($ch); return $r; }$url = 'http://wx.qlogo.cn/mmopen/xu0fLo9waqKSTDO7j0kSO41O5Luq3LB6ozUvY4O7OsXUWNicB49fBs8nGYzoqcwGDARQZHpVuic4JSDngEVjVo10BoiaPd0iciaOb/0';$a = curl_file_get_contents($url);file_put_contents('uploads/2.jpg', $a);
This will be quick ....
This should be the network reason, just download a picture, with what method can not feel the difference at all