Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 18, 2024 via composer

react/event-loop v1.5.0

ReactPHP's core reactor event loop that libraries can use for evented I/O.
Package summary
Share
0
issues
1
license
1
MIT
Package created
10 May 2012
Version published
13 Nov 2023
Maintainers
5
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
react/event-loop@v1.5.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of react/event-loop 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does react/event-loop do?

React/Event-Loop is a core component of ReactPHP's suite of tools aimed at handling asynchronous I/O operations. It serves as a conduit for interoperability, allowing various asynchronous libraries to utilize the same event loop. This makes managing event-driven I/O operations significantly easier and more efficient. React/Event-Loop provides a common LoopInterface that can be targeted by any library, enabling them to run harmoniously within a single event loop.

How do you use react/event-loop?

To use react/event-loop, you'll need to include it in your PHP project. If you are familiar with Composer, you can easily install ReactPHP's EventLoop by running the command composer require react/event-loop. After the installation, you can use it with PHP bundling tools to take advantage of its functionality in your web application.

Here is a simple quickstart usage example:

<?php

use React\EventLoop\Loop;

require __DIR__ . '/vendor/autoload.php';

$server = stream_socket_server('tcp://127.0.0.1:8080');
stream_set_blocking($server, false);

Loop::addReadStream($server, function ($server) {
    $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) {
        $written = fwrite($conn, $data);
        if ($written === strlen($data)) {
            fclose($conn);
            Loop::removeWriteStream($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";
});

This code showcases the creation of an asynchronous HTTP server with react/event-loop. To begin with, stream_socket_server is used to create the server socket and set it to non-blocking mode. A stream is then added to the event loop with Loop::addReadStream. This script also establishes a periodic timer that shows the current memory usage every five seconds.

Where are the react/event-loop docs?

The official documentation for react/event-loop is available on the project's GitHub page (https://github.com/reactphp/event-loop). The readme file provides a detailed overview of the package's functionality, including how to use it for building server-side applications, handling signals and timers, and working with stream and future ticks. It also gives a rundown of different LoopInterface methods such as addTimer, addReadStream, addWriteStream, and several others. Beginners and experienced developers alike will find the docs to be a thorough guide for incorporating react/event-loop into their PHP projects.