PHP code example of forge-templates / php-openswoole-kit

1. Go to this page and download the library: Download forge-templates/php-openswoole-kit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

forge-templates / php-openswoole-kit example snippets


$router->get('/health', HealthController::class);
$router->get('/users/{id}', UserShowController::class);

final class HealthController
{
    public function __invoke(Request $req, Response $res): void
    {
        $res->json([
            'status' => 'ok',
        ]);
    }
}
text
project/
├─ bootstrap/
│  └─ app.php              # App bootstrap (env + config loader)
├─ public/
│  └─ server.php          # Entry point (OpenSwoole server)
├─ config/
│  └─ config.php          # Central configuration
├─ app/
│  ├─ Http/
│  │  ├─ Controllers/     # Application controllers
│  │  ├─ Request.php      # Request abstraction
│  │  └─ Response.php     # Response abstraction
│  ├─ Routing/            # Core routing engine
│  ├─ Routes/             # Route registration layer
│  └─ Support/            # Env, Logger, Error handling
├─ storage/
│  └─ logs/              # Application logs
├─ .env
└─ composer.json
bash
composer create-project forge-templates/php-openswoole-kit
bash
php public/server.php
text
[PRODUCTION] My OpenSwoole Service started on 0.0.0.0:8077