An asynchronous ClamAV wrapper written in PHP with amphp/socket

Overview

amphp-clamav

An asynchronous ClamAV wrapper written with amphp/socket

Installing

composer require pato05/amphp-clamav

Examples

Ping and scan of a file/directory

examples/scan.php:

<?php
require_once __DIR__ . '/../vendor/autoload.php';

use Amp\ClamAV;
use Amp\Loop;

Loop::run(function () {

    echo 'connecting...' . PHP_EOL;

    $clamav = new ClamAV;
    if (yield $clamav->ping()) {
        echo 'connected successfully!' . PHP_EOL;
    } else {
        echo 'connection failed!' . PHP_EOL;
        return;
    }
    echo 'running test scan...' . PHP_EOL;
    /** @var \Amp\ClamAV\ScanResult */
    $result = yield $clamav->scan('/tmp/eicar.com');
    echo (string) $result . PHP_EOL;
});

Scanning from a InputStream (in this case a File instance which implements InputStream)

examples/scan_stream.php:

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Amp\ClamAV;
use Amp\Loop;

Loop::run(function () {
    echo 'connecting...' . PHP_EOL;

    $clamav = new ClamAV;
    if (yield $clamav->ping()) {
        echo 'connected!' . PHP_EOL;
    } else {
        echo 'connection failed.' . PHP_EOL;
        return;
    }
    echo 'running a streamed scan...' . PHP_EOL;

    /** @var \Amp\File\File */
    $file = yield \Amp\File\openFile('/tmp/eicar.com', 'r');

    /** @var \Amp\ClamAV\ScanResult */
    $res = yield $clamav->scanFromStream($file);
    yield $file->close(); // always close files to avoid memory leaks
    echo (string) $res . PHP_EOL;
});

Using a TCP/IP socket instead

When instantiating the ClamAV class, you can also define your socket URI, therefore if you want to use a TCP/IP socket instead of a UNIX one, do:

$clamav = new ClamAV('tcp://IP:PORT');

Be aware that TCP/IP sockets may be slightly slower than UNIX ones.

Using MULTISCAN

MULTISCAN is supported but can only be used on non-session instances (due to a ClamAV limitation).

MULTISCAN allows you to make a multithreaded scan.

$result = yield $clamav->multiscan('FILEPATH');

Differences between running a session and without

Sessions run on the same socket connection, while non-session instances will reconnect to the socket for each command. The library supports both, it's up to you deciding which to use.

Instantiating a session is pretty straight forward, just use the ClamAV::session() method like this:

$clamSession = yield (new ClamAV)->session();

Though you MUST end every session by using the method Session::end():

yield $clamSession->end();

Be aware that in a session you can only execute ONE COMMAND AT A TIME, therefore, if you want to run more than one command in parallel, use the main ClamAV class instead.

Multiple Sessions can also be instantiated.

You might also like...
The Official Vultr API PHP Wrapper

WIP - This is not the final API Client. Unstable release use with caution. Vultr API PHP Client. Getting Started Must have a PSR7, PSR17, and PSR18 Co

A telegram bot to check credit cards. written in php & py

MRBANKER BOT A telegram bot to check credit cards. written in php & py. You can find me on telegram STEP1: goto botfather create a bot copy the token

A library written in PHP to interact with Coinbase Pro via API.

A library written in PHP to interact with Coinbase Pro via API.

The library provides convenient access to the Epoint.az API from applications written in the PHP language.

Tural/Epoint library/SDK The library provides convenient access to the Epoint.az API from applications written in the PHP language. It includes a pre-

The library provides convenient access to the Epoint.az API from applications written in the PHP language.

Tural/Epoint library/SDK The library provides convenient access to the Epoint.az API from applications written in the PHP language. It includes a pre-

laravel wrapper for dicom images services

laravel wrapper for dicom images services

An elegant wrapper around Google Vision API
An elegant wrapper around Google Vision API

STILL UNDER DEVELOPMENT - DO NOT USE IN PRODUCTION Requires PHP 8.0+ For feedback, please contact me. This package provides an elegant wrapper around

A Laravel wrapper for thephpleague's Fractal package

laravel-api-response A Laravel wrapper for thephpleague's Fractal package Install Via Composer composer require lykegenes/laravel-api-response Then, a

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Owner
Pato05
Creating things, I guess?
Pato05
Wise-php - This library is written to accommodate the wise API's use in php projects With Wise

Wise-php - This library is written to accommodate the wise API's use in php projects With Wise you can automate payments, connect your business tools, and create ways to manage your finances. You can also power your cross-border and domestic payouts.

Albert Xhani 15 Nov 17, 2022
A PHP Stream wrapper for Amazon S3

S3StreamWrapper A simple stream wrapper for Amazon S3. Example <?php use S3StreamWrapper\S3StreamWrapper; S3StreamWrapper::register(); $options = a

Gijs Kunze 21 Nov 23, 2021
A PHP wrapper for Spotify's Web API.

Spotify Web API PHP This is a PHP wrapper for Spotify's Web API. It includes the following: Helper methods for all API endpoints: Information about ar

Jonathan Wilsson 796 Jan 8, 2023
Simple Curl based wrapper for Binance API for PHP scripts

Simple Curl based wrapper for Binance API for PHP scripts Feaures API support for SPOT data/trading FAPI/DAPI support for futures data/trading Curl-on

Mr Crypster 22 May 1, 2022
Google Drive Api Wrapper by PHP

GoogleDrive Api Wrapper usage at first you need to create oauth client on google cloud platform. so go to the your google console dashboard and create

Arash Abedi 2 Mar 24, 2022
Twitch Helix API PHP Wrapper for Laravel

Laravel Twitch PHP Twitch Helix API Wrapper for Laravel 5+ ⚠️ Changes on May 01, 2020 Since May 01, 2020, Twitch requires all requests to contain a va

Roman Zipp 87 Dec 7, 2022
Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP

MailChimp API Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP. I hate complex wrappers. This lets you get from the MailChimp API do

Drew McLellan 2k Dec 22, 2022
Google Translator Api Wrapper For Php Developers.

Google Translator Api Wrapper For Php Developers.

Roldex Stark 2 Oct 12, 2022
Laravel wrapper for the Facebook Graph PHP 8 SDK

Laravel Facebook Graph SDK Installation Getting started with Laravel Facebook Graph is easy - first, install the package via composer composer require

Joel Butcher 44 Dec 8, 2022
OVHcloud APIs lightweight PHP wrapper

Lightweight PHP wrapper for OVHcloud APIs - The easiest way to use OVHcloud APIs in your PHP applications - Compatible with PHP 7.4, 8.0, 8.1 - Not affiliated with OVHcloud

Germain Carré 3 Sep 10, 2022