somov / yii2-large-file-downloader
支持多流下载文件。具有断点续传和监控进度的功能
1.0.6
2022-03-13 21:22 UTC
Requires
- ext-curl: *
- yiisoft/yii2: >=2.0.38
- yiisoft/yii2-httpclient: *
Requires (Dev)
- codeception/base: ^2.2.3
- codeception/specify: ~0.4.3
- codeception/verify: ~0.3.1
- phpunit/phpunit: ~5
This package is auto-updated.
Last update: 2024-09-19 23:58:09 UTC
README
它是一个基于 yii2-httpclient 的yii2扩展
支持多流下载文件。具有断点续传和监控进度的功能。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist somov/yii2-large-file-downloader "~1.0"
或添加
"somov/yii2-large-file-downloader": "~1.0"
到您的 composer.json
文件的 require 部分。
使用方法
/** @var \somov\lfd\Client $client */ $client = Yii::createObject([ 'class' => \somov\lfd\Client::class, //'threadCount' => 5, //'resumeDownload' => true, //'tmpAlias' => '@runtime/downloads' ]); $client->on(\somov\lfd\Client::EVENT_PROGRESS, function ($event){ /** @var \somov\lfd\ProgressEvent $event */ echo $event->percent; }); //Download file $fileName = $client->download("https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4")->data; $size = filesize($fileName); echo $size;
使用命令控制器
Configure the command in your main application configuration:
'controllerMap' => [ 'downloader' => '\somov\lfd\CommandController' ],
一旦安装并配置了此扩展,只需在您的命令行中直接使用即可
yii downloader https://speed.hetzner.de/1GB.bin -c 20