Skip to content

Instantly share code, notes, and snippets.

@gboddin
Last active November 1, 2017 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gboddin/ebe1277c67e1f5254ddb563b8eedfdbf to your computer and use it in GitHub Desktop.
Save gboddin/ebe1277c67e1f5254ddb563b8eedfdbf to your computer and use it in GitHub Desktop.
Big file download in PHP ( guzzle )

This way ensure the file is streamed to the disk instead of memory.

  1. Install guzzle
composer require guzzlehttp/guzzle:~6.0
  1. Use get.php
<?php
require(__DIR__.'/vendor/autoload.php');
use GuzzleHttp\Client;
$client = new Client();
$resource = fopen('/tmp/ubuntu.iso', 'w');
$client->request('GET', 'http://releases.ubuntu.com/16.04.3/ubuntu-16.04.3-desktop-amd64.iso', ['sink' => $resource]);
fclose($resource);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment