Forked from devNoiseConsulting/gist:fb6195fbd09bfb2c1f81367dd9e727ed
Created
December 4, 2018 19:56
-
-
Save niladam/cb7b4102c6bf0ad077d558055ba24b30 to your computer and use it in GitHub Desktop.
Download large files using Guzzle 6.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use GuzzleHttp\Client; | |
$url = "https://domain.tld/large-file.mp4"; | |
$tmpFile = tempnam(sys_get_temp_dir(), 'guzzle-download'); | |
$client = new Client(array( | |
'base_uri' => '', | |
'verify' => false, | |
'sink' => $tmpFile, | |
'curl.options' => array( | |
'CURLOPT_RETURNTRANSFER' => true, | |
'CURLOPT_FILE' => $handle | |
) | |
)); | |
$res = $client->get($url); | |
echo $res->getStatusCode() . "\n"; | |
echo $res->getHeaderLine('content-type') . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment