2017 © Pedro Peláez
 

library reactphp-event-loop

Event loop abstraction layer that libraries can use for evented I/O.

image

werkint/reactphp-event-loop

Event loop abstraction layer that libraries can use for evented I/O.

  • Wednesday, November 16, 2016
  • by nick4fake
  • Repository
  • 4 Watchers
  • 0 Stars
  • 1,418 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 83 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

EventLoop Component

Build Status Code Climate, (*1)

Event loop abstraction layer that libraries can use for evented I/O., (*2)

In order for async based libraries to be interoperable, they need to use the same event loop. This component provides a common LoopInterface that any library can target. This allows them to be used in the same loop, with one single run call that is controlled by the user., (*3)

In addition to the interface there are some implementations provided:, (*4)

  • StreamSelectLoop: This is the only implementation which works out of the box with PHP. It does a simple select system call. It's not the most performant of loops, but still does the job quite well., (*5)

  • LibEventLoop: This uses the libevent pecl extension. libevent itself supports a number of system-specific backends (epoll, kqueue)., (*6)

  • LibEvLoop: This uses the libev pecl extension (github). It supports the same backends as libevent., (*7)

  • ExtEventLoop: This uses the event pecl extension. It supports the same backends as libevent., (*8)

All of the loops support these features:, (*9)

  • File descriptor polling
  • One-off timers
  • Periodic timers
  • Deferred execution of callbacks

Usage

Here is an async HTTP server built with just the event loop., (*10)

    $loop = React\EventLoop\Factory::create();

    $server = stream_socket_server('tcp://127.0.0.1:8080');
    stream_set_blocking($server, 0);
    $loop->addReadStream($server, function ($server) use ($loop) {
        $conn = stream_socket_accept($server);
        $data = "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nHi\n";
        $loop->addWriteStream($conn, function ($conn) use (&$data, $loop) {
            $written = fwrite($conn, $data);
            if ($written === strlen($data)) {
                fclose($conn);
                $loop->removeStream($conn);
            } else {
                $data = substr($data, $written);
            }
        });
    });

    $loop->addPeriodicTimer(5, function () {
        $memory = memory_get_usage() / 1024;
        $formatted = number_format($memory, 3).'K';
        echo "Current memory usage: {$formatted}\n";
    });

    $loop->run();

Note: The factory is just for convenience. It tries to pick the best available implementation. Libraries SHOULD allow the user to inject an instance of the loop. They MAY use the factory when the user did not supply a loop., (*11)

The Versions

16/11 2016

dev-master

9999999-dev

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

asynchronous event-loop

16/11 2016

dev-queue-fix

dev-queue-fix

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

asynchronous event-loop

08/03 2016

v0.4.2

0.4.2.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

asynchronous event-loop

14/06 2014

dev-singularity

dev-singularity

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

asynchronous event-loop

26/02 2014

v0.4.1

0.4.1.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

event-loop

02/02 2014

v0.4.0

0.4.0.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

event-loop

21/07 2013

0.3.x-dev

0.3.9999999.9999999-dev

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

21/07 2013

v0.3.4

0.3.4.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

09/07 2013

v0.3.3

0.3.3.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

15/01 2013

v0.3.0

0.3.0.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

05/01 2013

v0.2.7

0.2.7.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

26/12 2012

v0.2.6

0.2.6.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

13/11 2012

v0.2.3

0.2.3.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

10/09 2012

v0.2.0

0.2.0.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

event-loop

12/07 2012

v0.1.1

0.1.1.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

event-loop

11/07 2012

v0.1.0

0.1.0.0

Event loop abstraction layer that libraries can use for evented I/O.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

event-loop