Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save devNoiseConsulting/fb6195fbd09bfb2c1f81367dd9e727ed to your computer and use it in GitHub Desktop.
Save devNoiseConsulting/fb6195fbd09bfb2c1f81367dd9e727ed to your computer and use it in GitHub Desktop.
Download large files using Guzzle 6.3
<?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";
@reorg-greg
Copy link

Should $handle be $tmpFile?

@muhammadsikandarkhatri
Copy link

I forked this gist.

Check the complete code here
https://gist.github.com/skndrkhtr5/9ab734456a95dff5014e1f31a8ddcad0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment