Created
April 8, 2013 21:59
-
-
Save romainneutron/5340930 to your computer and use it in GitHub Desktop.
Download large files using Guzzle
This file contains 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 | |
use Guzzle\Http\Client; | |
require __DIR__ . '/vendor/autoload.php'; | |
$tmpFile = tempnam(sys_get_temp_dir(), 'guzzle-download'); | |
$handle = fopen($tmpFile, 'w'); | |
$client = new Client('', array( | |
Client::CURL_OPTIONS => array( | |
'CURLOPT_RETURNTRANSFER' => true, | |
'CURLOPT_FILE' => $handle | |
) | |
)); | |
$client->get('http://domain.tld/large-file.mp4')->send(); | |
fclose($handle); |
Doesn't work anymore with the latest version (6.1.11):
PHP Fatal error: Undefined class constant 'CURL_OPTIONS' in ....
Check out the sink documentation here:
http://docs.guzzlephp.org/en/latest/request-options.html#sink
How should this work if we use the HttpClient interface type hint? I should be more specific, if we're using php-http/httplug for a generic interface, how do you use the sink option?
I forked this gist to use Guzzle 6.3. https://gist.github.com/devNoiseConsulting/fb6195fbd09bfb2c1f81367dd9e727ed
I still need to test with large files, but the code will write the file to disk.
I forked @devNoiseConsulting.
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
👍 thanks for this! I had to figure out how to test downloading a zip file and then I needed to find it and unzip it. Your code helped a ton.