PHPackages                             zealphp/zealphp - 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. zealphp/zealphp

ActiveLibrary[Framework](/categories/framework)

zealphp/zealphp
===============

Coroutine-native PHP framework on OpenSwoole — async HTTP, WebSocket, streaming, and real-time applications.

v0.4.6(today)57014[8 issues](https://github.com/sibidharan/zealphp/issues)[5 PRs](https://github.com/sibidharan/zealphp/pulls)MITPHPPHP ^8.3CI passing

Since Jul 1Pushed today3 watchersCompare

[ Source](https://github.com/sibidharan/zealphp)[ Packagist](https://packagist.org/packages/zealphp/zealphp)[ Docs](https://php.zeal.ninja)[ GitHub Sponsors](https://github.com/sibidharan)[ RSS](/packages/zealphp-zealphp/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (12)Versions (77)Used By (0)

ZealPHP — A PHP HTTP Server (built on OpenSwoole)
=================================================

[](#zealphp--a-php-http-server-built-on-openswoole)

ZealPHP runs PHP as the HTTP server itself — not a CGI worker behind one. Built on **OpenSwoole**, it ships HTTP, WebSocket, SSE, coroutines, shared memory, timers, and task workers as first-class primitives because the server stays alive between requests. Existing PHP code runs unchanged via ext-zealphp function overrides; new features go async without a separate Node or Go service. Alpha — see stability note below.

[![Packagist Version](https://camo.githubusercontent.com/16fad05fa949ff99b307efb585f5289f02ba1bf6abb6e3fc29e1a6e5c732604e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a65616c7068702f7a65616c7068703f7374796c653d666c61742d73717561726526636f6c6f723d6f72616e6765266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/zealphp/zealphp) [![Packagist Downloads](https://camo.githubusercontent.com/a570181cd138c2bb123142ba94bc242622d953ef099d0f394a4bb27e7401a532/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a65616c7068702f7a65616c7068703f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/zealphp/zealphp) [![License](https://camo.githubusercontent.com/4e56c440759d0f37f7958472ec46151ebc8f6d732d8a1b971c0980af5956f35d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a65616c7068702f7a65616c7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zealphp/zealphp)[![Ask DeepWiki](https://camo.githubusercontent.com/0f5ae213ac378635adeb5d7f13cef055ad2f7d9a47b36de7b1c67dbe09f609ca/68747470733a2f2f6465657077696b692e636f6d2f62616467652e737667)](https://deepwiki.com/sibidharan/zealphp) [![GitHub stars](https://camo.githubusercontent.com/7e044f77a36f8f1a46ca40ca7f06938479e96ed75fb79b1d5403ce4507aad0ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f7a65616c7068702f7a65616c7068703f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465)](https://github.com/sibidharan/zealphp/stargazers) [![PHP 8.3+](https://camo.githubusercontent.com/fb0a84ab8a9738d607e205202045bc46378a5284fcf16a8d7b1870c1aa1973d5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d3737376262343f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/) [![PHP tested](https://camo.githubusercontent.com/eb1c618c036e79ecafaffaf8383ccb5e83f59ac86648a1029f95426ba2d48479/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7465737465642d504850253230382e33253230253743253230382e34253230253743253230382e352d2d6578706572696d656e74616c2d3737376262343f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://github.com/sibidharan/zealphp/actions/workflows/tests.yml) [![Stability](https://camo.githubusercontent.com/a03a73ef60cbefea96a6f176b64d208ffd419f99201df96745eab61872d5c4d3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d616374697665253230616c7068612d6f72616e67653f7374796c653d666c61742d737175617265)](CHANGELOG.md)[![CI](https://github.com/sibidharan/zealphp/actions/workflows/tests.yml/badge.svg)](https://github.com/sibidharan/zealphp/actions/workflows/tests.yml) [![CodeQL](https://github.com/sibidharan/zealphp/actions/workflows/codeql.yml/badge.svg)](https://github.com/sibidharan/zealphp/actions/workflows/codeql.yml) [![gitleaks](https://github.com/sibidharan/zealphp/actions/workflows/gitleaks.yml/badge.svg)](https://github.com/sibidharan/zealphp/actions/workflows/gitleaks.yml) [![Coverage](https://camo.githubusercontent.com/38238bcaa6e7b92f34d93eac3b12a8913a2e4c07215387b49e2f8e1dc50bf7ee/68747470733a2f2f636f6465636f762e696f2f67682f7369626964686172616e2f7a65616c7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/sibidharan/zealphp) [![PHPStan](https://camo.githubusercontent.com/64bf2427b34e4a24ee24c117c3636ba08b2ec74c9a92b9711092aa255d41a9d8/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d2532467369626964686172616e2532467a65616c7068702532466d61737465722532462e6769746875622532466261646765732532467068707374616e2e6a736f6e)](phpstan.neon) [![Mutation MSI](https://camo.githubusercontent.com/0d8ad1b785d6b14ddd5305a39d13ee653e072d0c979b39fd2b1a719e5aa5ef4a/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d2532467369626964686172616e2532467a65616c7068702532466d61737465722532462e6769746875622532466261646765732532466d75746174696f6e2e6a736f6e)](https://github.com/sibidharan/zealphp/actions/workflows/mutation.yml) [![OpenSSF Scorecard](https://camo.githubusercontent.com/d0f2a9a17684a5ac61f130d4d78f5605acbfdc19868fb347f9e71791ed74142b/68747470733a2f2f6170692e736563757269747973636f726563617264732e6465762f70726f6a656374732f6769746875622e636f6d2f7369626964686172616e2f7a65616c7068702f6261646765)](https://securityscorecards.dev/viewer/?uri=github.com/sibidharan/zealphp) [![SBOM](https://camo.githubusercontent.com/e80e858317310472332d41c8cad9236851da0fbf042c39ac6e6dcbf51949cd65/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53424f4d2d4379636c6f6e6544582d626c75653f7374796c653d666c61742d737175617265)](https://github.com/sibidharan/zealphp/actions/workflows/sbom.yml)[![OpenSwoole](https://camo.githubusercontent.com/6700ca488f18fbbdf16abfeb742d2581d69c3a2342b0581ae5364696e9ec8f87/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4f70656e53776f6f6c652d32322532422d6666353732323f7374796c653d666c61742d737175617265)](https://openswoole.com/) [![Benchmarks](https://camo.githubusercontent.com/f9bcf47fd3d6661f440f8e96f2d672a49c556d5f28af1b541e02ca80ef9b2c44/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f62656e63686d61726b732d726570726f64756369626c652d737563636573733f7374796c653d666c61742d737175617265)](https://github.com/sibidharan/zealphp/tree/master/scripts) [![Contributor Covenant](https://camo.githubusercontent.com/901cf948334050957fac94da30b784c4ae9ab972b56202830e958b688aec9139/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6e7472696275746f72253230436f76656e616e742d322e312d3462616161613f7374796c653d666c61742d737175617265)](CODE_OF_CONDUCT.md) [![Sponsor](https://camo.githubusercontent.com/fca7ac9edcda04dbf5036fcdfb1eb568c3f362d756b3e9b382f8d2fd40a91e83/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f7369626964686172616e3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465)](https://github.com/sponsors/sibidharan)

**Homepage:**
Running `php app.php` serves the same docs site locally. Set `ZEALPHP_SITE_URL` if you want the rendered example URLs to point somewhere else. **Changelog:** [CHANGELOG.md](CHANGELOG.md) · **Design trade-offs:** [/design-tradeoffs](https://php.zeal.ninja/design-tradeoffs) · **Critique retrospective:** [CRITIC.md](CRITIC.md)

### PHP-FPM vs ZealPHP

[](#php-fpm-vs-zealphp)

PHP-FPMZealPHPProcess modelRequest-per-processLong-running serverWebSocket server—Built-inServer-Sent EventsWorkaroundNativeIn-memory state across requests—Shared memory (`Store`)Coroutines—OpenSwoole nativeBackground timers—`App::tick()`Needs Node.js for realtimeUsuallyNo> **Try it:** [`examples/tic-tac-toe/`](examples/tic-tac-toe/) is a multiplayer game with rooms, spectators, and live board sync — [~130 lines of PHP](examples/tic-tac-toe/app.php), no database, no Node.js.

---

Features
--------

[](#features)

FeatureDetails**Async coroutines**`go()` + `Channel` — thousands of concurrent requests per worker**SSR streaming**Generator `yield`, `$response->stream()`, `$response->sse()` — like React's `renderToPipeableStream`**WebSocket**`App::ws($path, $onMessage, $onOpen, $onClose)` — rooms, auth, binary, heartbeat**Pluggable Store/Counter**`Store::defaultBackend(Store::BACKEND_REDIS)` (or `ZEALPHP_STORE_BACKEND=redis`) flips storage from local `OpenSwoole\Table`/`Atomic` to Redis/Valkey with zero handler changes — cross-node shared state + persistence with one line. Tracked + TTL modes, per-worker coroutine pool, Lua-backed `Counter::compareAndSet`.**Cross-node messaging**`Store::publish($ch, $payload)` + `App::subscribe($ch, $handler)` for fire-and-forget pub/sub (cross-worker AND cross-host). `Store::publishReliable($stream, $payload)` + `App::subscribeReliable($stream, $handler)` for Streams-backed at-least-once delivery via consumer groups. The cross-server WebSocket routing pattern (owner-of-fd pushes; Redis routes to owner) lights up end-to-end. **Driver choice (both validated in v0.2.40):** Both phpredis (preferred when `ext-redis` is loaded) and predis SUBSCRIBE loops yield correctly under `OpenSwoole\Runtime::HOOK_ALL` — the production default in coroutine mode. phpredis is ~2× faster on hot CRUD; pick it when you can. One nuance: phpredis SUBSCRIBE blocks the worker WITHOUT HOOK\_ALL — if you disabled HOOK\_ALL explicitly, force `ZEALPHP_REDIS_PREFER=predis` for subscribers or re-enable HOOK\_ALL. See [`/store#pubsub`](https://php.zeal.ninja/store#pubsub).**Dynamic routing**`route()`, `nsRoute()`, `nsPathRoute()`, `patternRoute()` with reflection-based parameter injection**Middleware**PSR-15 stack — 30+ built-ins (CORS, ETag, Range, Compression, SessionStart, IniIsolation, Charset, CacheControl, Expires, Header, BasicAuth, IpAccess, RateLimit, ConcurrencyLimit, BlockPhpExt, MimeType, BodyRewrite, HostRouter, BodySizeLimit, Csrf, Redirect, Scoped, MergeSlashes, Referer, RequestHeader, Return, SetEnvIf, ContentEncoding, ContentLanguage, HealthCheck) — full Apache `mod_rewrite` / `mod_headers` / `mod_expires` and nginx `limit_req` / `auth_basic` parity — see the [middleware reference](https://php.zeal.ninja/middleware) for the full list**HTTP/1.1 compliance**HEAD, OPTIONS, 301/302/307/308 redirects, Cookie SameSite, ETag, OpenSwoole compression**Shared memory**`Store` (OpenSwoole\\Table) + `Counter` (OpenSwoole\\Atomic) — cross-worker state**Timers**`App::tick()`, `App::after()`, `App::onWorkerStart()` — per-worker recurring tasks**ZealAPI**File-based REST: drop `api/device/list.php` → `/api/device/list` works automatically**Templating**Nested `App::render()` / `App::renderToString()` — single `_master.php`, component-based**Sessions**All `session_*()` functions overridden via ext-zealphp — coroutine-safe, per-request isolation**Unit tests**PHPUnit 11 — extensive unit and integration test suites, all green**Benchmarks**OpenSwoole-powered concurrency with a modular `scripts/bench.sh` runner for wrk/ab sweeps through c=1000> **Performance:** 117k req/s text · 106k JSON · 50k templated with 4 HTTP workers under the full PSR-15 middleware stack, 0 failures across 150k requests. ZealPHP retains ~82% of OpenSwoole's raw throughput with the framework on top; numbers vary by workload, payload, and hardware.
>
> Reproduce in 60s: `./scripts/bench_vs_express.sh`. Full methodology, latency percentiles, concurrency sweep, and caveats: [PERF.md](PERF.md). **Stability:** Alpha (v0.2.x). API may change between minor versions until v1.0. Pin to a specific version in production.

> **Common Apache + nginx behavior coverage (v0.2.21).** ZealPHP ships built-in middlewares and server-level setters for the common `.htaccess` / `nginx.conf` patterns used by traditional PHP apps — rewrite-style routing, headers, expiry/cache rules, basic auth, IP access, rate limits, MIME types, request limits. This is coverage for migration use cases, not a byte-for-byte server replacement. 12 new middlewares (`HeaderMiddleware`, `BasicAuthMiddleware`, `RateLimitMiddleware`, `CharsetMiddleware`, `CacheControlMiddleware`, `ExpiresMiddleware`, `IpAccessMiddleware`, `ConcurrencyLimitMiddleware`, `BlockPhpExtMiddleware`, `MimeTypeMiddleware`, `BodyRewriteMiddleware`, `HostRouterMiddleware`) and 8 new configurables (`$server_admin`, `$canonical_name`, `$trusted_proxies` + `App::clientIp()`, `$access_log_format`, `LimitRequestFields` family, `$strip_trailing_slash`, `App::tryInclude()`) landed in v0.2.21. See the [middleware reference](https://php.zeal.ninja/middleware) and the [legacy-apps coverage matrix](https://php.zeal.ninja/legacy-apps) for the full story.

---

Why ZealPHP?
------------

[](#why-zealphp)

**The architectural shift: PHP becomes the HTTP server. The migration story is the on-ramp; the destination is "your existing PHP code, plus WebSockets/SSE/coroutines/shared memory/timers, all in one PHP application server."**

PHP powers ~71% of the web ([W3Techs](https://w3techs.com/technologies/details/pl-php)), but the default request-per-process model (PHP-FPM, mod\_php) keeps the interpreter warm yet discards request-local state, and gives PHP no native way to hold a persistent connection — so WebSocket/SSE features land in separate Node/Go sidecar processes. ZealPHP runs on **OpenSwoole** — a long-lived PHP server with native coroutines — and adds a framework layer that:

1. **Accepts many traditional PHP patterns unchanged (compatibility mode).** Drop `.php` files in `public/`. `session_start()`, `header()`, `$_GET`, `$_POST`, `setcookie()`, `echo` all route through ext-zealphp overrides into per-request state. Many WordPress sites run through the CGI worker bridge — see [zealphp-wordpress](https://github.com/sibidharan/zealphp-wordpress) for the showcase and documented limits. Compatibility is a migration on-ramp, not a guarantee that every PHP application is safe to drop in without an audit.
2. **Adds async primitives when you want them.** `go()`, `Channel`, WebSocket, SSE, shared memory (`Store` / `Counter`), timers, task workers — all framework-native, no extra services.
3. **Lets you migrate file by file.** Start with fallback routing on day one; opt into coroutine mode when you're ready. No big-bang rewrite.

### vs other ways to make PHP async

[](#vs-other-ways-to-make-php-async)

- **vs PHP-FPM / mod\_php** — FPM keeps workers warm but discards request-local memory and treats PHP as a CGI worker, not the HTTP server. ZealPHP IS the HTTP server: caches survive across requests, and SSE/WebSocket connections are much cheaper to keep open than under request-per-process PHP (real capacity still depends on file descriptors, heartbeat policy, and OS tuning).
- **vs Laravel Octane** — Octane wraps Swoole inside a Laravel kernel. ZealPHP is framework-agnostic and exposes the runtime primitives directly. If you're on Laravel and want it faster, use Octane.
- **vs FrankenPHP / RoadRunner** — Go servers fronting PHP. ZealPHP runs native PHP coroutines on OpenSwoole — no Go process in between.
- **vs ReactPHP / AMPHP** — Library collections you wire together. ZealPHP is the integrated framework on top.
- **vs raw Swoole / OpenSwoole** — ZealPHP adds routing, PSR-15 middleware, templates, session overrides, and the legacy bridge so you don't write `onRequest` handlers by hand.
- **vs Node.js** — Different language and ecosystem; not the same trade-off space. If you're already in JS, stay in JS. ZealPHP exists for teams that want OpenSwoole-style concurrency without leaving PHP, or that need to bring a PHP codebase along.

[Full comparison →](https://php.zeal.ninja/why-zealphp)

---

Quick Start
-----------

[](#quick-start)

### Docker (fastest path — no system setup)

[](#docker-fastest-path--no-system-setup)

```
git clone https://github.com/sibidharan/zealphp.git
cd zealphp
docker compose up app
# → http://localhost:8080
```

### Composer (requires PHP 8.3+, OpenSwoole, ext-zealphp)

[](#composer-requires-php-83-openswoole-ext-zealphp)

```
# New project
composer create-project zealphp/project:^0.4.6 my-project
cd my-project
php app.php
# → https://php.zeal.ninja
```

```
