PHPackages                             mrgreen/log-parser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. mrgreen/log-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

mrgreen/log-parser
==================

PHP Log Parser Library

09PHP

Since Jul 4Pushed 11y ago1 watchersCompare

[ Source](https://github.com/MrGreen2/log-parser)[ Packagist](https://packagist.org/packages/mrgreen/log-parser)[ RSS](/packages/mrgreen-log-parser/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Web server access Log Parser
============================

[](#web-server-access-log-parser)

[![Build Status](https://camo.githubusercontent.com/bdf603ea569f5a1a9f0d9fc1a44e96d8b2a234d4d810a63be3839a645bc5dc48/68747470733a2f2f7472617669732d63692e6f72672f6b6173736e65722f6c6f672d7061727365722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/kassner/log-parser)

Install
-------

[](#install)

Using composer:

```
php composer.phar require kassner/log-parser:dev-master

```

Usage
-----

[](#usage)

Simply instantiate the class :

```
$parser = new \Kassner\LogParser\LogParser();
```

And then parse the lines of your access log file :

```
$lines = file('/var/log/apache2/access.log', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
    $entry = $parser->parse($line);
}
```

Where `$entry` object will hold all data parsed.

```
stdClass Object
(
    [host] => 193.191.216.76
    [logname] => -
    [user] => www-data
    [stamp] => 1390794676
    [time] => 27/Jan/2014:04:51:16 +0100
    [request] => GET /wp-content/uploads/2013/11/whatever.jpg HTTP/1.1
    [status] => 200
    [responseBytes] => 58678
)
```

You may customize the log format (by default it matches the [Apache common log format](https://httpd.apache.org/docs/2.2/en/logs.html#common))

```
# default Nginx format :
$parser->setFormat('%h %l %u %t "%r" %>s %O "%{Referer}i" \"%{User-Agent}i"');
```

Supported format strings
------------------------

[](#supported-format-strings)

Here is the full list of [log format strings](https://httpd.apache.org/docs/2.2/en/mod/mod_log_config.html#formats) supported by Apache, and whether they are supported by the library :

Supported?Format StringProperty nameDescriptionY%%percentThe percent signY%&gt;statusstatusY%AlocalIpLocal IP-addressY%aremoteIpRemote IP-addressN%B-Size of response in bytes, excluding HTTP headers.Y%bresponseBytesSize of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent.N%D-The time taken to serve the request, in microseconds.N%f-FilenameY%hhostRemote hostN%H-The request protocolY%IreceivedBytesBytes received, including request and headers, cannot be zero. You need to enable mod\_logio to use this.N%k-Number of keepalive requests handled on this connection. Interesting if KeepAlive is being used, so that, for example, a '1' means the first keepalive request after the initial one, '2' the second, etc...; otherwise this is always 0 (Y indicating the initial request). Available in versions 2.2.11 and later.Y%llognameRemote logname (from identd, if supplied). This will return a dash unless mod\_ident is present and IdentityCheck is set On.Y%mrequestMethodThe request methodY%OsentBytesBytes sent, including headers, cannot be zero. You need to enable mod\_logio to use this.Y%pportThe canonical port of the server serving the requestN%P-The process ID of the child that serviced the request.N%q-The query string (prepended with a ? if a query string exists, otherwise an empty string)Y%rrequestFirst line of requestN%R-The handler generating the response (if any).N%s-Status. For requests that got internally redirected, this is the status of the *original* request --- %&gt;s for the last.N%T-The time taken to serve the request, in seconds.Y%ttimeTime the request was received (standard english format)Y%uuserRemote user (from auth; may be bogus if return status (%s) is 401)Y%UURLThe URL path requested, not including any query string.Y%vserverNameThe canonical ServerName of the server serving the request.Y%VcanonicalServerNameThe server name according to the UseCanonicalName setting.N%X-Connection status when response is completed: X = connection aborted before the response completed. + = connection may be kept alive after the response is sent. - = connection will be closed after the response is sent.N%{Foobar}C-The contents of cookie Foobar in the request sent to the server. Only version 0 cookies are fully supported.N%{Foobar}e-The contents of the environment variable FOOBARY%{Foobar}i\*HeaderThe contents of Foobar: header line(s) in the request sent to the server. Changes made by other modules (e.g. mod\_headers) affect this. If you're interested in what the request header was prior to when most modules would have modified it, use mod\_setenvif to copy the header into an internal environment variable and log that value with the %{VARNAME}e described above.N%{Foobar}n-The contents of note Foobar from another module.N%{Foobar}o-The contents of Foobar: header line(s) in the reply.N%{format}p-The canonical port of the server serving the request or the server's actual port or the client's actual port. Valid formats are canonical, local, or remote.N%{format}P-The process ID or thread id of the child that serviced the request. Valid formats are pid, tid, and hextid. hextid requires APR 1.2.0 or higher.N%{format}t-The time, in the form given by format, which should be in strftime(3) format. (potentially localized) (This directive was %c in late versions of Apache 1.3, but this conflicted with the historical ssl %{var}c syntax.)Exceptions
----------

[](#exceptions)

If a line does not match with the defined format, an `\Kassner\LogParser\FormatException` will be thrown.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.5% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6087617?v=4)[MrGreen2](/maintainers/MrGreen2)[@MrGreen2](https://github.com/MrGreen2)

---

Top Contributors

[![kassner](https://avatars.githubusercontent.com/u/301255?v=4)](https://github.com/kassner "kassner (53 commits)")[![MrSecure](https://avatars.githubusercontent.com/u/1155636?v=4)](https://github.com/MrSecure "MrSecure (7 commits)")[![kbsali](https://avatars.githubusercontent.com/u/53676?v=4)](https://github.com/kbsali "kbsali (3 commits)")[![MrGreen2](https://avatars.githubusercontent.com/u/6087617?v=4)](https://github.com/MrGreen2 "MrGreen2 (2 commits)")

### Embed Badge

![Health badge](/badges/mrgreen-log-parser/health.svg)

```
[![Health](https://phpackages.com/badges/mrgreen-log-parser/health.svg)](https://phpackages.com/packages/mrgreen-log-parser)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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