PHPackages                             forge-templates/php-openswoole-kit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. forge-templates/php-openswoole-kit

ActiveProject[Framework](/categories/framework)

forge-templates/php-openswoole-kit
==================================

Production-ready PHP OpenSwoole boilerplate with clean architecture, request/response layer, and scalable structure.

v1.0.0(3mo ago)02MITPHPPHP ^8.2

Since Apr 16Pushed 3mo agoCompare

[ Source](https://github.com/forge-templates/php-openswoole-kit)[ Packagist](https://packagist.org/packages/forge-templates/php-openswoole-kit)[ RSS](/packages/forge-templates-php-openswoole-kit/feed)WikiDiscussions 1.x Synced 1w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

OpenSwoole Production Skeleton
==============================

[](#openswoole-production-skeleton)

A high-performance, production-ready OpenSwoole HTTP server skeleton built with modern PHP architecture principles.

This project follows a **clean architecture approach**, using PSR-4 autoloading, strict separation of concerns, structured logging, and a lightweight routing system optimized for high concurrency workloads.

---

Features
--------

[](#features)

- High-performance OpenSwoole HTTP server
- PSR-4 autoloading (no manual `require` in app layer)
- Clean architecture (Http / Routing / Support / Controllers)
- Centralized configuration system
- `.env` support via `phpdotenv`
- Production-grade logging (Monolog with rotating files)
- Global error &amp; exception handling (Laravel-like behavior)
- Lightweight router with dynamic routes (`/users/{id}`)
- JSON-first API response layer
- Stateless request lifecycle (optimized for workers)
- Ready for horizontal scaling

---

📁 Project Structure
-------------------

[](#-project-structure)

```
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

```

---

Requirements
------------

[](#requirements)

- PHP 8.2+
- OpenSwoole extension
- Composer

---

Installation
------------

[](#installation)

```
composer create-project forge-templates/php-openswoole-kit
```

---

Environment Setup
-----------------

[](#environment-setup)

Run :

```
cp .env.example .env
```

Or create `.env` file in the project root:

```
APP_NAME="My OpenSwoole Service"
APP_ENV=production
APP_DEBUG=false
APP_TIMEZONE=Asia/Aden

HOST=0.0.0.0
PORT=8077

MAX_REQUEST=10000
REQUEST_TIMEOUT_MS=30000
REQUEST_BODY_SIZE_LIMIT=2097152

RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX=60

LOG_LEVEL=info
LOG_DAYS=14
```

---

Running the Server
------------------

[](#running-the-server)

```
php public/server.php
```

You should see:

```
[PRODUCTION] My OpenSwoole Service started on 0.0.0.0:8077

```

---

🧠 Architecture Overview
-----------------------

[](#-architecture-overview)

### 1. Bootstrap Layer

[](#1-bootstrap-layer)

- Loads Composer autoload
- Loads `.env`
- Builds configuration array

### 2. Configuration Layer

[](#2-configuration-layer)

- Centralized config via `config/config.php`
- Environment values injected through `Env` helper
- No direct `getenv()` usage in business logic

### 3. HTTP Layer

[](#3-http-layer)

- `Request` wraps OpenSwoole request
- `Response` handles output (JSON / Text / HTML)
- Stateless per request lifecycle

### 4. Routing Layer

[](#4-routing-layer)

- Static + dynamic routes supported
- Supports:

    - `/users/{id}`
    - `/api/*`
- Clean controller binding

### 5. Support Layer

[](#5-support-layer)

- Global error handler (exceptions, fatal errors)
- Structured logging (Monolog)
- Central environment helper

---

Routing Example
---------------

[](#routing-example)

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

Controller example:

```
final class HealthController
{
    public function __invoke(Request $req, Response $res): void
    {
        $res->json([
            'status' => 'ok',
        ]);
    }
}
```

---

Logging
-------

[](#logging)

Logs are stored in:

```
storage/logs/app.log

```

Features:

- Rotating logs
- Structured output
- Error + exception capture
- Production-safe format

---

Error Handling
--------------

[](#error-handling)

- Global exception handler
- Fatal error capture
- Debug mode support
- Production-safe JSON error responses

---

Performance Notes
-----------------

[](#performance-notes)

Designed for:

- Long-running OpenSwoole workers
- High concurrency traffic
- Minimal per-request overhead
- No repeated bootstrapping per request

---

🔐 Security Notes
----------------

[](#-security-notes)

- Sensitive values stored in `.env`
- Config layer isolates environment access
- Body size limits enforced
- Safe JSON decoding
- Controlled error output in production

---

📄 License
---------

[](#-license)

MIT

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance81

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

99d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/114437356?v=4)[Sr / Ajmal Alkhaledi](/maintainers/AjmalAlkhaledi)[@AjmalAlkhaledi](https://github.com/AjmalAlkhaledi)

---

Top Contributors

[![AjmalAlkhaledi](https://avatars.githubusercontent.com/u/114437356?v=4)](https://github.com/AjmalAlkhaledi "AjmalAlkhaledi (3 commits)")

### Embed Badge

![Health badge](/badges/forge-templates-php-openswoole-kit/health.svg)

```
[![Health](https://phpackages.com/badges/forge-templates-php-openswoole-kit/health.svg)](https://phpackages.com/packages/forge-templates-php-openswoole-kit)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.5k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k16](/packages/tempest-framework)[lion/bundle

Lion-framework configuration and initialization package

122.4k4](/packages/lion-bundle)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[doppar/framework

The Doppar Framework

4112.4k14](/packages/doppar-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
