【问题标题】:Async file_put_contents/file_get_contents?异步 file_put_contents/file_get_contents?
【发布时间】:2019-06-22 14:32:31
【问题描述】:

有没有办法用php异步下载文件?

找到this answer,但似乎无法使用此方法下载文件

问题是我需要从 API 下载文件,但下载所有图像需要一段时间,并且 URL 在调用后不可用。

谢谢

【问题讨论】:

  • 您是否看过 Guzzle 库,它实现了并行下载多个内容的 A+ 承诺?
  • @GuillaumeSTLR 我不知道这个库,但感谢它完美运行

标签: php asynchronous curl file-get-contents file-put-contents


【解决方案1】:

感谢@GuillaumeSTLR,我设法用Guzzle Library做到了

让它发挥作用。您所要做的就是:

use GuzzleHttp\Client;

$client = new Client();
$client->getAsync($url, [ 'sink' => $file ]);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-02
  • 2013-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-30
  • 1970-01-01
相关资源
最近更新 更多