2017 © Pedro Peláez
 

library libevent

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

image

aza/libevent

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

  • Tuesday, May 28, 2013
  • by amal
  • Repository
  • 1 Watchers
  • 3 Stars
  • 10,670 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 2 Forks
  • 3 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

AzaLibEvent

Simple, powerful and easy to use OOP wrapper for the LibEvent PHP bindings., (*1)

https://github.com/Anizoptera/AzaLibEvent, (*2)

![Build Status][TravisImage], (*3)

Table of Contents

  1. Introduction
  2. Requirements
  3. Installation
  4. Examples
  5. Credits
  6. License
  7. Links

Introduction

Main features:, (*4)

  • 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

Installation

The recommended way to install AzaLibEvent is through composer. You can see package information on Packagist., (*5)

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

Examples

Example #1 - Polling STDIN using basic API

See examples/basic_api.php, (*6)

/**
 * 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

See examples/buffered_api.php, (*7)

/**
 * 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

AzaLibEvent is a part of Anizoptera CMF, written by Amal Samally (amal.samally at gmail.com) and AzaGroup team., (*8)

License

Released under the MIT license., (*9)

The Versions

28/05 2013

dev-master

9999999-dev https://github.com/Anizoptera/AzaLibEvent

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by AzaGroup Members

async event stream sockets libevent timers

28/05 2013

v1.1

1.1.0.0 https://github.com/Anizoptera/AzaLibEvent

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by AzaGroup Members

async event stream sockets libevent timers

27/02 2013

v1.0

1.0.0.0 https://github.com/Anizoptera/AzaLibEvent

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

  Sources   Download

MIT

The Requires

 

by AzaGroup Members

async event stream sockets libevent timers