jooservices / useragent
Deterministic, dataset-backed synthetic User-Agent profiles for tests and fixtures.
Requires
- php: >=8.5
- ext-json: *
- jooservices/dto: ^3.0 || ^4.0
Requires (Dev)
- captainhook/captainhook: ^5.23
- captainhook/plugin-composer: ^5.3
- friendsofphp/php-cs-fixer: ^3.65
- laravel/pint: ^1.18
- phpmd/phpmd: ^3.0
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
- squizlabs/php_codesniffer: ^3.12 || ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-29 22:08:59 UTC
README
PHP 8.5+ deterministic generator of coherent synthetic browser User-Agent profiles for tests, fixtures, and controlled client configuration.
Features
- Checksummed bundled dataset with provenance on every result
- Seeded, weighted, uniform, and round-robin profile selection
- Immutable fluent request builder and bounded unique batch generation
generatePool()for a list of ready-to-use User-Agent strings- Stable profile identity for logs and fixtures
- Non-interactive CLI with JSON and NDJSON output
Requirements
- PHP
>= 8.5 ext-jsonjooservices/dto ^3.0 || ^4.0(DTO v4 also requiresext-mbstring)
Installation
composer require jooservices/useragent:^4.1
Quick start
use JOOservices\UserAgent\Generator; $generator = Generator::create(); $pool = $generator->builder() ->chrome() ->windows() ->desktop() ->seed(42) ->generatePool(10);
Using the pool with jooservices/client
jooservices/client does not depend on this package. Install it separately when
you need HTTP requests; client ^4.6 supports DTO v3 and v4, as does this
package. The packages have independent version numbers.
use JOOservices\Client\Client\ClientBuilder; use JOOservices\UserAgent\Generator; $pool = Generator::create()->builder()->seed(42)->generatePool(10); $client = ClientBuilder::create()->withRotatingUserAgent($pool)->build();
The seed makes pool generation repeatable. The client picks a member of the pool independently for each request; that choice is not seeded by this package.
Command line
vendor/bin/useragent --help vendor/bin/useragent --browser=chrome --os=windows --seed=42 vendor/bin/useragent --count=10 --format=ndjson --seed=42
The CLI writes User-Agent strings as text, or complete generation results as JSON or NDJSON. Invalid options exit with status 2; generation errors exit with status 1.
Design notes
- Reuse one
Generatorinstance in long-running processes; it loads and validates the bundled dataset once. - A User-Agent string is synthetic metadata, not browser emulation.
- The package performs no network access and does not accept a caller-provided dataset path.
Documentation
Development
make build
make install
make lint
make test
make ci
Community
License
MIT — see LICENSE.