如何优化 clamav cl_scanfile 使其更快?平均扫描文件大约需要 15-20 秒。因此,如果在一种形式中我有 2 个上传字段,则需要将近 40 秒或更长时间,这将导致 php max execution time 错误。
我宁愿不改变php的执行时间。
有没有办法做到这一点?
我的代码将是这样的:
function upload() {
...
// Checking element type based on element id.
// if element type == file, check the file type. Based on the result, halt (redirect to failure) or continue
foreach ($this->_controller->data['FormSubmission'] as $elementId => $fieldValue) {
...
...
//Checking The File for Virus
$retcode = cl_scanfile($fieldValue["tmp_name"], $virus_name);
//if Virus not found
if ($retcode != CL_VIRUS) {
//Check Directory if uploadPath is not a directory, make it
if (!is_dir($uploadPath)) {
mkdir($uploadPath, 0777, TRUE);
}
//filename
$now = date('Ymd-His');
$fileName = $now . '-' . $elementId . $fieldValue["name"];
$fullFilePath = $uploadPath . '/' . $fileName;
$uploading = move_uploaded_file($fieldValue["tmp_name"], $fullFilePath);
// change the value to uploadPath for ul/dl
$this->_controller->data["FormSubmission"][$elementId] = $fullFilePath;
} else {
//If Virus found, don't upload anything
$this->_controller->data["FormSubmission"][$elementId] = "";
}