sineflow / clamav
ClamAV PHP Client for Symfony
v2.1.0
2026-03-05 17:56 UTC
Requires
- php: ^8.2
- ext-sockets: *
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
- symfony/yaml: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.5
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2026-03-05 19:19:46 UTC
README
This library is a PHP client for working with a ClamAV daemon. It also provides optional Symfony integration.
Requirements:
You need to have ClamAV installed and configured to accept socket and/or network connections: https://docs.clamav.net/manual/Installing.html
Installation
$ composer require sineflow/clamav
Usage as a standalone library
$scanner = new Scanner(new ScanStrategyClamdUnix($socket)); $scanner = new Scanner(new ScanStrategyClamdNetwork($host, $port));
Usage as a Symfony bundle
Enable the bundle
// config/bundles.php return [ // ... Sineflow\ClamAV\Bundle\SineflowClamAVBundle::class => ['all' => true], ];
Configuration:
sineflow_clam_av: strategy: clamd_unix socket: "/var/run/clamav/clamd.ctl"
or
sineflow_clam_av: strategy: clamd_network host: 127.0.0.1 port: 3310
Scanning files
use Sineflow\ClamAV\Scanner; use Sineflow\ClamAV\Exception\FileScanException; use Sineflow\ClamAV\Exception\SocketException; public function myAction(Scanner $scanner) { try { $scannedFile = $scanner->scan($file); if (!$scannedFile->isClean()) { echo $scannedFile->getVirusName(); } } catch (SocketException $e) { ... } catch (FileScanException $e) { ... } }
Scanning streams
When the file is not on the local filesystem or not accessible to the ClamAV daemon (e.g. files stored via Flysystem in S3, SFTP, etc.), you can use scanStream() to send the file contents directly to ClamAV via its INSTREAM protocol.
use Sineflow\ClamAV\Scanner; use Sineflow\ClamAV\Exception\FileScanException; use Sineflow\ClamAV\Exception\SocketException; // In a real application, the stream would typically come from // Flysystem's readStream(), an HTTP response, or similar source. public function myAction(Scanner $scanner) { $stream = fopen('/path/to/file', 'rb'); try { $scannedFile = $scanner->scanStream($stream, 'my-upload.pdf'); if (!$scannedFile->isClean()) { echo $scannedFile->getVirusName(); } } catch (SocketException $e) { ... } catch (FileScanException $e) { ... } finally { fclose($stream); } }
Running tests
docker compose run --rm phpunit
docker compose down