-
-
Save CoreText/50be216ab5039eab75c4abeeda1ecca5 to your computer and use it in GitHub Desktop.
Limit CURL so it doesn't download huge files
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 | |
# 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