Forked from devNoiseConsulting/gist:fb6195fbd09bfb2c1f81367dd9e727ed
Created
May 20, 2019 15:58
-
-
Save rafpro/c113a8ede6bed4da99c16ceb2562ac92 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