Skip to content

Instantly share code, notes, and snippets.

@CoreText
Forked from ozh/curl.php
Created November 26, 2021 02:28
Show Gist options
  • Save CoreText/50be216ab5039eab75c4abeeda1ecca5 to your computer and use it in GitHub Desktop.
Save CoreText/50be216ab5039eab75c4abeeda1ecca5 to your computer and use it in GitHub Desktop.
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