Skip to content

Instantly share code, notes, and snippets.

@iprodev
Created December 14, 2018 19:32
Show Gist options
  • Save iprodev/4f3691e43460a737c10f92bc74c8ca57 to your computer and use it in GitHub Desktop.
Save iprodev/4f3691e43460a737c10f92bc74c8ca57 to your computer and use it in GitHub Desktop.
PHP : Limit CURL so it doesn't download huge files
<?php
# with a callback
$sizeLimit = 100000;
curl_setopt($ch, CURL_PROGRESSFUNCTION, function ($ch, $totalBytes, $receivedBytes) use ($sizeLimit) {
if ($totalBytes > $sizeLimit) {
return 1; // return non-zero value to abort transfer
}
});
# And check the error (using curl_errno()) for CURLE_ABORTED_BY_CALLBACK, if i want to know the reason is size limit.
# source: https://www.reddit.com/r/PHP/comments/641uud/is_there_any_easy_way_to_limit_curl_via_php_so_it/dg12n30/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment