Documentation/Launching the application/Swoole

Swoole

Open Swoole (previously known as Swoole) is a high-performance platform for asynchronous execution of subprocesses in PHP.

Swoole is installed as an extension for PHP. Currently, Swoole is supported only for Linux and Mac.

It's important to note that Swoole does not work with xDebug, the most popular debugging tool in the PHP ecosystem, and is also poorly compatible with some other profiling and monitoring tools.

For the application to function correctly when launched using this technology, it must be developed with support for asynchronous mode.

In asynchronous mode, the loaded framework configurations, classes, initialized services, and cached data are reused, which significantly accelerates performance.
However, there are distinctive features, such as the need to monitor memory leaks more closely and eliminate blocking operations, and many familiar third-party libraries do not support asynchronous mode.
Storing state in the logical parts of the application becomes undesirable, especially if it is related to a request.

The framework's RollbackInterface is designed for state resetting after each asynchronous request.

For Swoole, you will need to modify the /public/index.php file to ensure the HLEB2 framework runs in a loop. A basic working example:

<?php
// File /public/index.php

// use Swoole\Http\{Request, Response, Server};
use OpenSwoole\Http\{RequestResponseServer};

include 
__DIR__ "/../vendor/autoload.php";

$http = new Server('127.0.0.1'9504);
$http->set([
    
'log_file' => '/dev/stdout'
]);

// Framework initialization outside the loop.
$framework = new Hleb\HlebAsyncBootstrap(__DIR__);

$http->on('request', function ($requestResponse $response) use ($framework) {
    
// Getting an object with a response.
    
$res $framework->load($request)->getResponse();
    foreach (
$res->getHeaders() as $name => $header) {
        
$response->header($name$header);
    }
    
$response->status($res->getStatus(), (string)$res->getReason());
    
$response->end($res->getBody());
});

$http->start();

The Swoole server is started with the console command:

$php ./public/index.php

According to the configuration, the application will be accessible at the address:
http://localhost:9504

RoadRunner Server Using Hosting

Page translated: chatgpt 4-o
Back to top