lmz/phpanalysis
A PHP Chinese word segmentation library based on PHPAnalysis. It splits Chinese text into words using dictionary rules, supports UTF-8/GBK input, and is useful for keyword extraction, search indexing, and basic text analysis in PHP projects.
Architecture fit. lmz/phpanalysis is a plain-PHP Chinese word segmentation (中文分词) library — a repackaging/fork of the classic phpanalysis algorithm (dictionary-driven, rule-based matching, not a statistical or ML model). It ships no Laravel service provider, facade, config file, or auto-discovery. In a Laravel codebase it therefore belongs strictly in the infrastructure/utility layer, behind an interface you own — never called directly from controllers or domain services. Its natural landing spots are search indexing (tokenizing Chinese content before feeding a search engine), keyword/tag extraction, snippet generation, and simple content classification. It is a reasonable fit for those narrow jobs and a poor fit for anything resembling production-grade NLP (NER, sentiment, domain-specific term extraction).
Integration feasibility. High mechanically, low organizationally. Composer-installable, pure PHP, no native extensions, no external services — a one-line dependency. Wrapping it in a ChineseSegmenter contract plus a small service provider is a half-day task. The real effort is verification, not integration: confirming the autoload namespace actually matches the fork's structure, confirming the bundled dictionary path is resolvable under a packaged/vendored deploy, and confirming it runs on your target PHP version.
Technical risk. This is the dominant concern and it is severe:
composer.json platform constraints. PHP 8.2+ compatibility is unverified and must be tested, not assumed.Key questions to resolve before committing.
Stack fit. Pure PHP means it drops into any Laravel 10/11 application without touching the runtime, container, or queue infrastructure. It also means it inherits PHP-FPM's per-request lifecycle — relevant for dictionary loading (see Operational Impact). There is no framework coupling to unwind, which cuts both ways: nothing to uninstall later, but also no framework affordances to lean on.
Migration path. Treat this as a vendored component, not a dependency. Concretely: fork it into an internal repository (or pin the exact commit with a composer.lock checksum), add CI, add a PHP version matrix, and add characterization tests over a golden input/output corpus so that any future bump is verifiable. Then wrap it:
App\Contracts\Segmenter interface with a single segment(string): array method.PhpAnalysisSegmenter implementation owning instantiation and dictionary configuration.This wrapper is the actual deliverable — it is what makes the choice reversible. If quality proves insufficient, you swap the binding for a jieba-php implementation or an HTTP client to a Python/jieba service without touching call sites.
Compatibility. Validate three axes independently: PHP version (run the test suite on 8.1/8.2/8.3), mbstring/iconv availability in the runtime image, and input encoding. Standardize on UTF-8 at the boundary and convert inside the adapter if required, so encoding quirks never escape the wrapper.
Sequencing.
Maintenance. Assume you own this outright. With 2 stars and 0 dependents there is no realistic prospect of upstream fixes, security patches, or PHP-version upkeep. Budget roughly 2–4 engineer-days per year for dependency hygiene plus whatever dictionary curation the business requires — and dictionary curation is ongoing work, not a one-off, if segmentation quality matters to the product. This is the single largest hidden cost and should be stated explicitly in any business case.
Support. No community, no Stack Overflow footprint, no issue-triage history to mine. Internal documentation and the characterization test suite become the only support surface. Escalation path is "whoever wrote the wrapper."
Scaling. Segmentation is CPU-bound and single-threaded per request. The dominant scaling lever is avoiding per-request dictionary load: use opcache preloading, a singleton-bound segmenter within Octane/Swoole workers, or move bulk operations (catalog indexing, backfills) to queued batch jobs where a resident process amortizes the load across thousands of documents. For interactive, low-volume use (a query-time tokenizer) it will be fine. For high-QPS search indexing it will become a bottleneck before anything else in the stack does.
Failure modes to instrument.
memory_limit check in CI and a startup smoke test.composer.json constraints blocking a framework upgrade. Mitigate by vendoring/forking rather than tracking upstream.Ramp-up. Using the wrapper correctly takes an engineer under a day. Understanding the internals well enough to extend the dictionary, debug encoding issues, or port it forward takes about a week — and that knowledge will be concentrated in one or two people, which is itself a risk worth naming. There is no external tutorial base to fall back on, so plan for pairing rather than self-service onboarding.
How can I help you explore Laravel packages today?