PHPackages                             aza/libevent - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. aza/libevent

ActiveLibrary[Queues &amp; Workers](/categories/queues)

aza/libevent
============

AzaLibEvent - Simple, powerful and easy to use OOP wrapper for the LibEvent PHP bindings. Component from Anizoptera CMF.

v1.1(12y ago)329.0k[3 issues](https://github.com/Anizoptera/AzaLibEvent/issues)1MITPHPPHP &gt;=5.2

Since Feb 27Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Anizoptera/AzaLibEvent)[ Packagist](https://packagist.org/packages/aza/libevent)[ Docs](https://github.com/Anizoptera/AzaLibEvent)[ RSS](/packages/aza-libevent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (1)

AzaLibEvent
===========

[](#azalibevent)

Simple, powerful and easy to use OOP wrapper for the [LibEvent](http://libevent.org/) PHP bindings.

[![Build Status](https://camo.githubusercontent.com/021c12b00c23935bf39c21f25f61f5d782db3874bfda90915a5b5ab48b2fff86/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f416e697a6f70746572612f417a614c69624576656e742e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/Anizoptera/AzaLibEvent)

Table of Contents
-----------------

[](#table-of-contents)

1. [Introduction](#introduction)
2. [Requirements](#requirements)
3. [Installation](#installation)
4. [Examples](#examples)
    - [Polling STDIN using basic API](#example-1---polling-stdin-using-basic-api)
    - [Polling STDIN using buffered event API](#example-2---polling-stdin-using-buffered-event-api)
5. [Credits](#credits)
6. [License](#license)
7. [Links](#links)

Introduction
------------

[](#introduction)

**Main features:**

- Convenient, fully documented and tested in production API;
- Timers and intervals system (look at `EventBase::timerAdd`);
- Special base reinitializing for forks (look at `EventBase::reinitialize`);
- Error handling with exceptions;
- Automatic resources cleanup;

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

[](#requirements)

- PHP 5.2.0 (or later);
- [libevent](http://php.net/libevent);

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

[](#installation)

The recommended way to install AzaLibEvent is [through composer](http://getcomposer.org). You can see [package information on Packagist](https://packagist.org/packages/aza/libevent).

```
{
	"require": {
		"aza/libevent": "~1.0"
	}
}
```

Examples
--------

[](#examples)

#### Example #1 - Polling STDIN using basic API

[](#example-1---polling-stdin-using-basic-api)

See [examples/basic\_api.php](examples/basic_api.php)

```
/**
 * Callback function to be called when the matching event occurs
 *
 * @param resource $fd     File descriptor
 * @param int      $events What kind of events occurred. See EV_* constants
 * @param array    $args   Event arguments - array(Event $e, mixed $arg)
 */
function print_line($fd, $events, $args)
{
	static $max_requests = 0;
	$max_requests++;

	/**
	 * @var $e    Event
	 * @var $base EventBase
	 */
	list($e, $base) = $args;

	// exit loop after 10 writes
	if ($max_requests == 10) {
		$base->loopExit();
	}

	// print the line
	echo fgets($fd);
}

// Create base
$base = new EventBase;

// Setup and enable event
$ev = new Event();
$ev->set(STDIN, EV_READ|EV_PERSIST, 'print_line', $base)
		->setBase($base)
		->add();

// Start event loop
$base->loop();
```

#### Example #2 - Polling STDIN using buffered event API

[](#example-2---polling-stdin-using-buffered-event-api)

See [examples/buffered\_api.php](examples/buffered_api.php)

```
/**
 * Callback to invoke where there is data to read
 *
 * @param resource $buf  File descriptor
 * @param array    $args Event arguments - array(EventBuffer $e, mixed $arg)
 */
function print_line($buf, $args)
{
	static $max_requests;
	$max_requests++;

	/**
	 * @var $e    EventBuffer
	 * @var $base EventBase
	 */
	list($e, $base) = $args;

	// exit loop after 10 writes
	if ($max_requests == 10) {
		$base->loopExit();
	}

	// print the line
	echo $e->read(4096);
}

/**
 * Callback to invoke where there is an error on the descriptor.
 * function(resource $buf, int $what, array $args(EventBuffer $e, mixed $arg))
 *
 * @param resource $buf  File descriptor
 * @param int      $what What kind of error occurred. See EventBuffer::E_* constants
 * @param array    $args Event arguments - array(EventBuffer $e, mixed $arg)
 */
function error_func($buf, $what, $args) {}

// I use Base::getEventBase() to operate always with the
// same instance, but you can simply use "new EventBase()"

// Get event base
$base = Base::getEventBase();

// Create buffered event
$ev = new EventBuffer(STDIN, 'print_line', null, 'error_func', $base);
$ev->setBase($base)->enable(EV_READ);

// Start loop
$base->loop();
```

Credits
-------

[](#credits)

AzaLibEvent is a part of [Anizoptera CMF](https://github.com/Anizoptera), written by [Amal Samally](http://azagroup.ru/about/#amal) (amal.samally at gmail.com) and [AzaGroup](http://azagroup.ru/) team.

License
-------

[](#license)

Released under the [MIT](LICENSE.md) license.

Links
-----

[](#links)

- [Composer package](https://packagist.org/packages/aza/libevent)
- [Last build on the Travis CI](http://travis-ci.org/Anizoptera/AzaLibEvent)
- [Project profile on the Ohloh](https://www.ohloh.net/p/AzaLibEvent)
- Other Anizoptera CMF components on the [GitHub](https://github.com/Anizoptera) / [Packagist](https://packagist.org/packages/aza)
- (RU) [AzaGroup team blog](http://azagroup.ru/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~90 days

Total

2

Last Release

4739d ago

PHP version history (2 changes)v1.0PHP &gt;=5.3.3

v1.1PHP &gt;=5.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/356b06126f37416ba259cc00868ae0960bad500f459186a25a7cc3b90c80fcb5?d=identicon)[amal](/maintainers/amal)

---

Top Contributors

[![art-shen](https://avatars.githubusercontent.com/u/423417?v=4)](https://github.com/art-shen "art-shen (37 commits)")

---

Tags

anizoptera-cmfcomposerdaemon-applicationslibeventpackagistphp-librarysocketstravisstreameventasyncsocketslibeventtimers

### Embed Badge

![Health badge](/badges/aza-libevent/health.svg)

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

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k123.4M323](/packages/amphp-amp)[react/socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP

1.3k116.9M402](/packages/react-socket)[workerman/phpsocket.io

A server side alternative implementation of socket.io in PHP based on Workerman

2.3k578.6k16](/packages/workerman-phpsocketio)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

92343.6M138](/packages/revolt-event-loop)[amphp/byte-stream

A stream abstraction to make working with non-blocking I/O simple.

393116.2M104](/packages/amphp-byte-stream)[icicleio/icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

1.1k150.9k14](/packages/icicleio-icicle)

PHPackages © 2026

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