Swoole\Coroutine\Http\Client->download

Declaration

<?php
Swoole\Coroutine\Http\Client->download(string $path, string $filename,  int $offset = 0)

Parameters

path

The path of the remote file to be downloaded.

filename

The filename of the remote file to be downloaded.

offset

The offset of the remote file to be downloaded.

Return

Description

Download file at the remote URL.

Example

<?php
use Swoole\Coroutine\HTTP\Client;

Co\run(function() {
    $host = 'www.swoole.co.uk';
    $cli = new Swoole\Coroutine\Http\Client($host, 443, true);
    $cli->set(['timeout' => -1]);
    $cli->setHeaders([
        'Host' => $host,
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => '*',
        'Accept-Encoding' => 'gzip'
    ]);
    $cli->download('/images/swoole-logo.svg', __DIR__ . '/swoole-logo.svg');
});