PHPackages                             hexydec/agentzero - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hexydec/agentzero

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hexydec/agentzero
=================

A zero knowledge library for extracting information from User-Agent strings

2.0.2(8mo ago)40100.2k—0.1%1[1 PRs](https://github.com/hexydec/agentzero/pulls)MITPHPPHP &gt;=8.1CI failing

Since Aug 5Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/hexydec/agentzero)[ Packagist](https://packagist.org/packages/hexydec/agentzero)[ Docs](https://github.com/hexydec/agentzero)[ RSS](/packages/hexydec-agentzero/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (19)Used By (0)

AgentZero: Fast User-Agent Detection
====================================

[](#agentzero-fast-user-agent-detection)

A library for extracting information from User-Agent strings very fast.

[![Licence: MIT](https://camo.githubusercontent.com/1be08aa7893603196bc3465a2235df43f54fab679741e5cdb07b9f513c5dd5d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e63652d4d49542d6c69676874677265792e737667)](https://camo.githubusercontent.com/1be08aa7893603196bc3465a2235df43f54fab679741e5cdb07b9f513c5dd5d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e63652d4d49542d6c69676874677265792e737667)[![Tests Status](https://github.com/hexydec/agentzero/actions/workflows/tests.yml/badge.svg)](https://github.com/hexydec/agentzero/actions/workflows/tests.yml)[![Code Coverage](https://camo.githubusercontent.com/7105578f6a8f83a5cbcb7b525264ec650103bebded2209fd736f31b2a577e946/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686578796465632f6167656e747a65726f2f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/hexydec/agentzero/code-structure/main/code-coverage)

Description
-----------

[](#description)

Doesn't match full UA strings or patterns, instead it extracts and categorises features from UA strings, so is faster, and can handle new UA strings or variations of common UA patterns.

Most User-Agent detection libraries rely on lists of regular expressions to match user agent string patterns and extract information. With lots of patterns you can do an ok job of getting this info, but it is not dynamic enough, which leads to minor variations or new UA strings not being captured, and they tend to be quite slow.

AgentZero is a simple string matching library that splits the user agent strings up into tokens to extract information from each part, leading to more complete information, more flexibility in capturing new user agent strings, and better performance.

You can try out AgentZero online at , or run the supplied `index.php` file after installation.

Usage
-----

[](#usage)

To use AgentZero:

```
$ua = $_SERVER['HTTP_USER_AGENT']; // or whatever UA you want e.g:
$ua = 'Mozilla/5.0 (Linux; Android 13; Pixel 7 Pro Build/TD1A.220804.031; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 Instagram 301.1.0.33.110 Android (33/13; 420dpi; 1080x2116; Google/google; Pixel 7 Pro; cheetah; cheetah; en_GB; 517986703)';
if (($browser = \hexydec\agentzero\agentzero::parse($ua)) !== false) {
	// use $browser
}
```

`parse()` returns `false` if the string is empty, longer than 2000 characters, or produces no recognisable tokens. Always check the return value before using the object. The returned value will be something like:

```
\hexydec\agentzero\agentzero (

	public readonly string $string => string 'Mozilla/5.0 (Linux; Android 13; Pixel 7 Pro Build/TD1A.220804.031; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 Instagram 301.1.0.33.110 Android (33/13; 420dpi; 1080x2116; Google/google; Pixel 7 Pro; cheetah; cheetah; en_GB; 517986703)';

	// categories
	public readonly ?string $type => string 'human';
	public readonly ?string $category => string 'mobile';

	// device
	public readonly ?string $vendor => string 'Google';
	public readonly ?string $device => string 'Pixel';
	public readonly ?string $model => string '7 Pro';
	public readonly ?string $build => string 'TD1A.220804.031';
	public readonly ?int $ram => null;

	// architecture
	public readonly ?string $processor => null;
	public readonly ?string $architecture => null;
	public readonly ?int $bits => null;
	public readonly ?string $cpu => null;
	public readonly ?int $cpuclock => null;

	// platform
	public readonly ?string $kernel => string 'Linux';
	public readonly ?string $platform => string 'Android';
	public readonly ?string $platformversion => string '13';

	// browser
	public readonly ?string $engine => string 'Blink';
	public readonly ?string $engineversion => string '116.0.0.0';
	public readonly ?string $browser => string 'Chrome';
	public readonly ?string $browserversion => string '116.0.0.0';
	public readonly ?string $browserstatus => 'previous';
	public readonly ?string $browserreleased => '2023-09-15';
	public readonly ?string $browserlatest => '133.0.6943.54';
	public readonly ?string $language => string 'en-GB';

	// app
	public readonly ?string $app => string 'Instagram';
	public readonly ?string $appname => string 'Instagram';
	public readonly ?string $appversion => string '301.1.0.33.110';
	public readonly ?string $framework => null;
	public readonly ?string $frameworkversion => null;
	public readonly ?string $url => null;

	// network
	public readonly ?string $nettype => null;
	public readonly ?string $proxy => null;

	// screen
	public readonly ?int $width => int 1080;
	public readonly ?int $height => int 2116;
	public readonly ?int $dpi => int 420;
	public readonly ?float $density => null;
	public readonly ?bool $darkmode => null;
);
```

You can read the [full list of properties here](docs/api.md).

### Client Hints

[](#client-hints)

AgentZero now supports processing client hints for improved user-agent information. You must request the client hints to improve the information delivered through the user-agent string:

```
// request client hints
\header('Accept-CH: Width, ECT, Device-Memory, Sec-CH-UA-Platform-Version, Sec-CH-UA-Model, Sec-CH-UA-Full-Version-List');

// retrieve client hints
$hints = \hexydec\agentzero\agentzero::getHints();

// parse
$az = \hexydec\agentzero\agentzero::parse($_SERVER['HTTP_USER_AGENT'], $hints);
```

Note that by using the `Accept-CH` header, you may receive client hints on subsequent requests, if you need the client hints on first call, use the `Critical-CH` header instead (Warning: This will cause an extra round trip as the browser must re-request the first page).

### Browser Versions

[](#browser-versions)

You can determine the date the browser was released, latest version, and status, by setting where the version file should be cached:

```
$config = [
	'versionscache' => __DIR__.'/cache/versions.json'
];
$az = \hexydec\agentzero\agentzero::parse($_SERVER['HTTP_USER_AGENT'], [], $config);
var_dump(
	$az->browserstatus,  // "nightly", "canary", "beta", "current", "previous", "outdated" (2+ years old), or "legacy" (5+ years old)
	$az->browserreleased, // date the browser version was released, e.g. "2024-01-15"
	$az->browserlatest   // latest known version number of the browser
);
```

The browser version information is sourced from [my browser versions project](https://github.com/hexydec/versions).

Supported Features
------------------

[](#supported-features)

AgentZero supports a wide range of architectures, browsers, rendering engines, platforms, devices, languages, and crawlers. [Access the full list on the Supported Features page](docs/support.md).

Installation
------------

[](#installation)

The easiest way to get up and running is to use composer:

```
$ composer require hexydec/agentzero

```

Test Suite
----------

[](#test-suite)

You can run the test suite like this:

### Linux

[](#linux)

```
$ vendor/bin/phpunit

```

### Windows

[](#windows)

```
> vendor\bin\phpunit

```

Support
-------

[](#support)

AgentZero supports PHP version 8.1+.

Contributing
------------

[](#contributing)

If you find an issue with AgentZero, please create an issue in the tracker.

If you wish to fix an issue yourself, please fork the code, fix the issue, then create a pull request, and I will evaluate your submission.

Licence
-------

[](#licence)

The MIT License (MIT). Please see [License File](LICENCE) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance76

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 99.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~47 days

Recently: every ~83 days

Total

17

Last Release

260d ago

Major Versions

0.6.0 → 1.0.02024-01-25

1.3.1 → 2.0.02025-05-03

PHP version history (2 changes)0.1.0PHP &gt;=8.0

0.5.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/5257ffcb9e543c03368e1090d353092b40b1491d15cd3126d14d3d32975b6384?d=identicon)[hexydec](/maintainers/hexydec)

---

Top Contributors

[![hexydec](https://avatars.githubusercontent.com/u/743478?v=4)](https://github.com/hexydec "hexydec (147 commits)")[![thecrazybob](https://avatars.githubusercontent.com/u/20065018?v=4)](https://github.com/thecrazybob "thecrazybob (1 commits)")

---

Tags

phpuser-agentuser-agent-parseruseragentuseragentparserphpbrowseruser agents

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hexydec-agentzero/health.svg)

```
[![Health](https://phpackages.com/badges/hexydec-agentzero/health.svg)](https://phpackages.com/packages/hexydec-agentzero)
```

###  Alternatives

[foroco/php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing

1554.7M7](/packages/foroco-php-browser-detection)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)[renoki-co/clusteer

Clusteer is a Puppeteer wrapper written for PHP, with the super-power of parallelizing pages across multiple browser instances.

891.2k](/packages/renoki-co-clusteer)[luka-dev/headless-task-server-php

Helper for sending requests to luka-dev/headless-task-server

109.6k](/packages/luka-dev-headless-task-server-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
