keevitaja/language-detector-socket 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

keevitaja/language-detector-socket

最新稳定版本:v0.0.5

Composer 安装命令:

composer require keevitaja/language-detector-socket

包简介

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

README 文档

README

A high-performance language detection service written in PHP 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.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,

    // Path to store the worker process ID file
    'workerPidFile' => '/tmp/language.detector.worker.pid',

    // Path to store the worker log file
    'workerLogFile' => '/tmp/language.detector.worker.log',

    // Path to store the worker an stdout log file
    'workerStdoutFile' => '/tmp/language.detector.worker.stdout.log',

    // Whether to run the worker as a daemon process
    'workerDemonize' => false,
]

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-18