onion / event-loop
Requires
- onion/interfaces: dev-master
- onion/promise: @dev
- psr/event-dispatcher: ^1.0
Requires (Dev)
- infection/infection: ^0.27.0
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.13
Suggests
- ext-ev: For the libev loop implementation
- ext-event: For the libevent loop implementation
- ext-uv: For the libuv loop implementation (see https://github.com/symplely/ext-uv)
- symplely/uv-ffi: FFI bindings for libuv allowing for compilation-free cross-platform usage
This package is auto-updated.
Last update: 2024-10-11 14:42:55 UTC
README
This is the async event loop that entirely relies on PHP 8.1 Fibers in order to provide native async functionality. By:
- Introducing a
coroutine
function to do execution on the event loop - Add
tick
function that allows for handling control back to the event loop to play nice with other coroutines Introduce custom stream wrapper (async://
) that uses signals to better break IO operations transparently for the applications.Patching the nativefile://
stream to handle all (except.php
files, since it causes race conditions with autoloader/file inclusion) transparently.
Known issues
When working with symplely/uv-ffi
you should manually call
scheduler()->start()
to start the event loop explicitly and
not rely on the automated start, because the FFI extension gets
unloaded, before the full script termination.
Functions
channel
- a function that creates either buffered or un-buffered
channel for exchanging data between 2 or more coroutines. The
type of channel is determined if any value is provided to its $size
parameter
coroutine
- a function that adds the provided function to the event
loop to be executed with the provided arguments
tick
- a signal wrapper, that is intended for complex/heavy code in
order to "mark" point at which the function can handle back control to
the event loop in order to allow it to execute other scheduled tasks.
(this should be used for "low level" code and thus transparent for the
end-user)
signal
- this this function is used to "signal" the event loop to
interrupt the currently running task until the provided callback
indicates that it should be resumed and optionally passing a value
that is the result of the execution
read
- wait for the given stream to become readable and execute the function provided
write
- same as read
but for writing
is_pending
- checks if a given stream has data that is to be read/written at the time of execution
sleep
- non-blocking sleep function that suspends the coroutine it is executed in until a given time