Download the PHP package flightphp/async without Composer
On this page you can find all versions of the php package flightphp/async. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flightphp/async
More information about flightphp/async
Files in flightphp/async
Package async
Short Description Package to allow you to run Flight on top of asynchronous frameworks like Swoole, ReactPHP, Amp, etc.
License MIT
Informations about the package async
What is Async?
Async is a package for the Flight framework that allows you to run your Flight apps in asynchronous frameworks like ReactPHP, Swoole, Amp, RoadRunner, Workerman, Adapterman, etc. Currently only configured for Swoole and AdapterMan
Requirements
- PHP 7.4 or higher
- Swoole extension (for Swoole usage)
- Flight framework 3.16.1 or higher
Installation
Installation is done through composer.
For Swoole support, you'll also need to install the Swoole extension:
Basic Usage (swoole)
Here is a simple example of how to use Flight Async where you can use Swoole or PHP-FPM as the server driver within the same project. This allows for you to develop your application using the PHP-FPM driver for better debugging and then switch to Swoole for production.
Setup
First you'll need the following files in your project:
index.php
swoole_server.php
SwooleServerDriver.php
Running the server
Development Mode (PHP Built-in Server)
To run the server with PHP-FPM for development, you can use the following command in your terminal:
Production Mode (Swoole)
When you are ready for production, you can switch to Swoole by running the following command:
Daemonizing the Swoole Server
If you want the Swoole server to run in the background (daemonized), you can modify the configuration in the SwooleServerDriver.php file by changing:
Note: Swoole runs as its own process and is not a full-fledged web server like Apache or Nginx. You'll likely want to use a reverse proxy with Nginx or Apache to handle SSL termination, load balancing, and serving static files.
Configuration
The SwooleServerDriver class includes several configuration options that you can customize:
worker_num: Number of worker processes (default: 4)max_request: Maximum requests per worker before restart (default: 8000)enable_coroutine: Enable coroutines for better concurrency (default: true)buffer_output_size: Output buffer size (default: 4MB)
Error Handling
The AsyncBridge handles Flight exceptions and converts them to appropriate HTTP responses. You can also add custom error handling in your routes:
License
Flight Async is released under the MIT license.