Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muhammadsikandarkhatri/9ab734456a95dff5014e1f31a8ddcad0 to your computer and use it in GitHub Desktop.
Save muhammadsikandarkhatri/9ab734456a95dff5014e1f31a8ddcad0 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');
$handle = fopen($tmpFile, 'w');
$client = new Client(array(
'base_uri' => '',
'verify' => false,
'sink' => storage_path('file.mp4'),
'curl.options' => array(
'CURLOPT_RETURNTRANSFER' => true,
'CURLOPT_FILE' => $handle
)
));
$client->get($url);
fclose($handle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment