blurgroup/quahog

此包已被放弃,不再维护。作者建议使用 xenolope/quahog 包。

ClamAV clamd守护进程的PHP客户端库

v3.0.0 2020-11-25 12:06 UTC

This package is auto-updated.

Last update: 2024-08-26 22:43:04 UTC


README

Build Status

Quahog是一个简单的PHP库,用于与clamd反病毒守护进程进行接口。它被编写为所有现有的用于从PHP接口ClamAV的库都使用exec('clamscan'),这并不是一个理想的解决方案,因为clamscan每次运行都会将整个数据库加载到内存中 - 这不是这样,所以它扫描得更快(快得多)。

安装

建议通过 composer 安装Quahog。

{
    "require": {
        "xenolope/quahog": "3.*"
    }
}

用法

// Create a new socket instance
$socket = (new \Socket\Raw\Factory())->createClient('unix:///var/run/clamav/clamd.ctl'); # Using a UNIX socket
$socket = (new \Socket\Raw\Factory())->createClient('tcp://192.168.1.1:3310'); # Using a TCP socket

// Create a new instance of the Client
$quahog = new \Xenolope\Quahog\Client($socket);

// Scan a file
$result = $quahog->scanFile('/tmp/virusfile');

// Scan a file or directory recursively
$result = $quahog->contScan('/tmp/virusdirectory');

// Scan a file or directory recursively using multiple threads
$result = $quahog->multiscanFile('/tmp/virusdirectory');

// Scan a stream, and optionally pass the maximum chunk size in bytes
$result = $quahog->scanStream(file_get_contents('/tmp/virusfile'), 1024);

// Scan multiple files in a row
$quahog->startSession();
$result = $quahog->scanFile('/tmp/virusfile');
$result2 = $quahog->scanFile('/tmp/virusfile2');
$quahog->endSession();

// Ping clamd
$result = $quahog->ping();

// Get ClamAV version details
$result = $quahog->version();

// View statistics about the ClamAV scan queue
$result = $quahog->stats();

// Reload the virus database
$quahog->reload();

// Shutdown clamd cleanly
$quahog->shutdown();

处理结果

// Result is an instance of \Xenolope\Quahog\Result.
$result = $quahog->scanFile('/tmp/virusfile');

// A result id of a session that was used.
$result->getId();

// The file name of the scanned file.
$result->getFilename();

// The reason why a scan resulted in a failure. Returns null if the scan was successful.
$result->getReason();

// A boolean value that is true, in case the scan was successful.
$result->isOk();

// A boolean value that is true, in case the scan failed. This is the opposite of isOk().
$result->hasFailed();

// A boolean value that is true, if a virus was found.
$result->isFound();

// A boolean value that is true, if an error happened.
$result->isError();

测试

要运行测试套件,您需要安装PHPUnit。转到项目根目录并运行

$ phpunit

许可证

Quahog在MIT许可证下发布