keevitaja/language-detector-socket

A high-performance PHP language detection service using Unix sockets and Efficient Language Detector.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/keevitaja/language-detector-socket

v0.0.2 2025-10-18 09:00 UTC

This package is auto-updated.

Last update: 2025-10-18 09:43:07 UTC


README

A high-performance PHP language detection service using Unix sockets and Efficient Language Detector.

Installation

composer require keevitaja/language-detector-socket

Important

Enable OPcache for CLI to avoid excessive CPU usage. The LanguageDetector library loads and compiles large language model data files on every request. Without OPcache, PHP will recompile these files repeatedly, causing significant CPU overhead.

opcache.enable_cli=1

Usage

Start the Server

use Keevitaja\LanguageDetectorSocket\Server;

$server = new Server([
    'socket' => '/tmp/language-detector.sock',
]);

$server->run();

Use the Client

use Keevitaja\LanguageDetectorSocket\Client;

$client = new Client([
    'socket' => '/tmp/language-detector.sock',
])->make();

$scores = $client->detect('Hello world');
// ['en' => 0.95, 'nl' => 0.03, ...]

$client->close();

Configuration defaults

[
    // Unix socket path
    'socket' => '/tmp/language-detector-socket.sock',

    // Number of worker processes
    'processes' => 1,

    // Connection timeout in seconds
    'timeout' => 10,

    // Limit detection to specific languages (null = all or ['en', 'nl'])
    'locales' => null,

    // Language model size (SMALL, MEDIUM, LARGE)
    'eldDataFile' => EldDataFile::SMALL,

    // Language code format (ISO639_1, ISO639_3)
    'eldFormat' => EldFormat::ISO639_1,
]