Created
December 14, 2018 19:32
-
-
Save iprodev/4f3691e43460a737c10f92bc74c8ca57 to your computer and use it in GitHub Desktop.
PHP : Limit CURL so it doesn't download huge files
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 | |
# 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