penven

博客园 首页 新随笔 联系 订阅 管理

Guzzle 流式下载数据/图片


use GuzzleHttp\Client;

$client   = new Client();
$response = $client->get('https://baidu.com/?p=%E6%B5%8B%E8%AF%95', ['stream' => true]);

$filePath = storage_path("image/".time().".jpg");
$resource = fopen($filePath, "w+");
while (!$response->getBody()->eof()) {
	$data = $response->getBody()->read(100);
	fputs($resource, $data);
	$this->line($data);
}
fclose($resource);
posted on 2023-05-16 16:56  penven  阅读(374)  评论(0编辑  收藏  举报