PHPackages                             spudley/apache-log-iterator - 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. spudley/apache-log-iterator

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

spudley/apache-log-iterator
===========================

An Apache log file processor class, in PHP

v2.1.0(9y ago)23395[1 issues](https://github.com/Spudley/ApacheLogIterator/issues)GPLv3PHPPHP ^5.3.3 || ^7.0

Since Dec 2Pushed 8y ago5 watchersCompare

[ Source](https://github.com/Spudley/ApacheLogIterator)[ Packagist](https://packagist.org/packages/spudley/apache-log-iterator)[ RSS](/packages/spudley-apache-log-iterator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (1)Versions (2)Used By (0)

ApacheLogIterator
=================

[](#apachelogiterator)

### Version 2.1.0

[](#version-210)

A small PHP class intended to simplify the processing of Apache log files within a PHP program.

Version History
---------------

[](#version-history)

- 2.1 Eh, fixed a few stupid mistakes made in 2.0.
- 2.0 Changed namespace; added composer.json; added to Packagist.
- 1.1 Added namespace.
- 1.0 Initial release

Requirements
------------

[](#requirements)

ApacheLogIterator has been tested under PHP 5.3.

This class has no external dependencies.

Functionality
-------------

[](#functionality)

ApacheLogIterator is a parser that aims to make the reading of your Apache log file as simple and as efficient as possible.

It extends the SPLFileObject. Normal usage of the SPLFileObject would be to open a file and use a foreach() loop to load each line from the file in turn. The ApacheLogIterator class extends this, such that instead of simply returning the raw data as read from the file, it processes it into a structured array.

Because it's an iterator, you can loop through it using foreach() without having to load the whole file into memory. This is particularly useful because Apache log files can be very large. Only the current record is in memory at any given time.

In addition, ApacheLogIterator comes with a small helper class called ApacheLogFields. This defines the structure of the log records. If your Apache is configured to produce logs in a different format to the ones described in the code, you may override the ApacheLogFiles class to define your own log record format as required.

Filtering the output is trivial: Since it is an Iterator class, you can filter the output using PHP's built-in [FilterIterator](http://php.net/manual/en/class.filteriterator.php).

Example for Standard Apache Logs
--------------------------------

[](#example-for-standard-apache-logs)

```
$logFile = "/path/to/apache/log/file";
$logIterator = new ApacheLogIterator($logFile);
foreach ($logIterator as $logRecord) {
    print_r($logRecord); //do whatever you want to here with the output array.
}

```

Example for Apache Error Logs
-----------------------------

[](#example-for-apache-error-logs)

```
$logFile = "/path/to/apache/log/error_file";
$logFields = new ApacheLogFields();
$logFields->regex = '/^\[(... ... \d\d \d\d:\d\d:\d\d \d\d\d\d)\] \[(error)\] \[.+ (.*)\] (.*,) (.*$)$/';
$logFields->fieldArray = array(
    'originalLogEntry',
    'logtime',
    'type',
    'remoteIP',
    'query',
    'referrer'
);
$logIterator = new ApacheLogIterator($logFile, $logFields);
foreach ($logIterator as $logRecord) {
    print_r($logRecord); //do whatever you want to here with the output array.
}

```

The output array looks something like this:

```
array (
    'originalLogEntry' => '*** the full log record, in case you need it ***',
    'localServer' => 'yourservername',
    'remoteIP' => '192.168.1.1',
    'datetime' => '21/Jul/2012:15:10:54 +0100',
    'method' => 'GET',
    'status' => '200',
    'bytes' => '32611',
    'referrer' => 'http://www.referralurl.com/',
    'userAgent' => 'Mozilla/5.0 (Windows NT 6.0; rv:13.0) Gecko/20100101 Firefox/13.0.1',
    'request' => array (
        'scheme' => 'http',
        'host' => 'mydomain.com',
        'path' => '/query.php',
        'query' => 'q=te57+1ng&submit=Search',
        'fullURL' => 'http://mydomain.com:/query.php?q=te57+1ng&submit=Search',
        'queryArgs' => array (
            'q' => 'te57 1ng',
            'submit' => 'Search',
        ),
    ),
)

```

Copyright and License
---------------------

[](#copyright-and-license)

This class was written by Simon Champion. Copyright Simon Champion and Connection Services Ltd.

It is released under the General Public License version 3 (GPLv3); see COPYING.txt for full license text. Please contact me if you require alternative licensing arrangements.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

3450d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a7e0e9e3e433f0c7fb045ce5f7fd334efb567a774b90a321886fa433e13882b?d=identicon)[Spudley](/maintainers/Spudley)

---

Top Contributors

[![Spudley](https://avatars.githubusercontent.com/u/1370806?v=4)](https://github.com/Spudley "Spudley (11 commits)")[![tingham](https://avatars.githubusercontent.com/u/265838?v=4)](https://github.com/tingham "tingham (2 commits)")[![radutopala](https://avatars.githubusercontent.com/u/647137?v=4)](https://github.com/radutopala "radutopala (1 commits)")

---

Tags

apacheiteratorlogsphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spudley-apache-log-iterator/health.svg)

```
[![Health](https://phpackages.com/badges/spudley-apache-log-iterator/health.svg)](https://phpackages.com/packages/spudley-apache-log-iterator)
```

PHPackages © 2026

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