A global event loop for ReactPHP.
Install the latest version with Composer.
composer require jsor/global-loop
Check the Packagist page for all available versions.
Typical applications use a single event loop. ReactPHP requires that you pass the loop instance around, eg. as argument to functions and class constructors.
This library allows to use a single event loop instance from everywhere by providing static global accessors.
The only requirement is to call the static Jsor\GlobalLoop::run()
at the
end of your program.
<?php
// Application runs here
Jsor\GlobalLoop::run();
You can then access the global loop instance from from inside your application
code by calling Jsor\GlobalLoop::get()
.
The default loop implementation is created using
React\EventLoop\Factory::create()
which picks the best available loop
implementation.
If you want to use a specific or custom loop implementation, you can set it with
Jsor\GlobalLoop::set()
at the beginning of your program.
<?php
Jsor\GlobalLoop::set(new MyLoopImplementation());
// Application runs here
Jsor\GlobalLoop::run();
Copyright (c) 2017 Jan Sorgalla. Released under the MIT License.