Data size limit PHP CURL
Because crawlers work needs to check the validity of multiple links, program analysis out the links sometimes exe, dmg file extension, etc., plus a sub file name or hard to detect, wanted to add a page to limit the size of the data, only take web content rather than download the file, after the internet search found the following method:
<?php
curl_setopt($cURL_Handle, CURLOPT_NOPROGRESS, false);
curl_setopt($cURL_Handle, CURLOPT_PROGRESSFUNCTION, function(
$DownloadSize, $Downloaded, $UploadSize, $Uploaded
){
// 已下载的档案大小超过1K(自订)责返回非零中断CURL
return ($Downloaded > (1 * 1024)) ? 1 : 0;
});
?>
Note that: the PHP documentation (https://www.php.net/manual/zh/function.curl-setopt.php) based on, CURLOPT_NOPROGRESS necessary to false, CURLOPT_PROGRESSFUNCTION to be effective.