omniphp / framework
OmniPHP — The universal PHP framework. Lightweight, Workerman-based: HTTP router & middleware, query builder & migrations, Redis Stream queue, template engine, cache, i18n and structured logging.
Requires
- php: >=8.4
- ext-json: *
- ext-mbstring: *
- ext-pdo: *
- owner888/php-async: ^1.0
- owner888/php-http: ^1.1
- owner888/php-mysql: ^1.0
- owner888/php-redis: ^1.0
- revolt/event-loop: ^1.1
- workerman/workerman: ^5.2.4
Requires (Dev)
- phpunit/phpunit: ^11.5
Suggests
- ext-redis: Required for the Redis cache driver, the Redis Stream queue and the rate-limit middleware
Provides
None
Conflicts
None
Replaces
None
README
The universal PHP framework. A lightweight, long-running application core built on Workerman: the process model of a daemon, the ergonomics of a classic web framework.
Status: extracted from a production Workerman application and published as a standalone package. The API is stable in practice but not yet frozen — expect
0.xreleases.
What's inside
| Namespace | Purpose |
|---|---|
OmniPHP\Application / CrashHandler / ArchitectureGuard |
One-call bootstrap (paths, .env, timezone, log level, i18n), three-tier fatal crash handler, and architectural lint guard |
OmniPHP\Http |
Kernel (Workerman onMessage entry), Router (static, grouped, typed params), Context (request/response helper), onion Middleware pipeline, Session, ExceptionHandler, ApiCode error-code envelope, built-in CORS / rate-limit / JSON-response middlewares |
OmniPHP\WebSocket |
Full-duplex Context (RFC 6455 protocol-level ping/pong, payload parsing, emit/error, broadcast), Broadcaster (connection pool, broadcast, sendToUid, zombie sweep), Gateway |
OmniPHP\Database |
PDO DB facade, fluent QueryBuilder, Schema blueprint + MigrationRunner, SoftDeletes, per-worker connection bootstrap |
OmniPHP\Model |
Thin active-record style base class on top of QueryBuilder |
OmniPHP\Queue |
Redis Stream job queue: Producer / Consumer / RedisQueue with priorities, delayed jobs, retries, dead-letter queue |
OmniPHP\View |
Compiled template engine with plugins, attribute parser and output caching |
OmniPHP\Cache |
Redis and FileCache drivers behind one Cache facade |
OmniPHP\Config / Lang |
PHP-array config loader; .ini based i18n with locale fallback |
OmniPHP\Logger |
Level-based logger with pluggable engines (FileEngine, ElasticsearchEngine, TelegramEngine) and LogRotator |
OmniPHP\Requests |
Fiber-aware HTTP client powered by owner888/php-http (HTTP/1.1, HTTP/2), requests-style |
A ready-made project layout lives in omniphp/omniphp
(composer create-project omniphp/omniphp myapp).
Everything runs inside Workerman worker processes: code is loaded once, connections are opened once per worker, and nothing assumes PHP-FPM's request-scoped lifecycle.
Requirements
- PHP 8.4+
- ext-openssl, ext-json, ext-mbstring, ext-pdo
- workerman/workerman ^5.2.4
- revolt/event-loop ^1.1
- owner888/php-async ^1.0
- owner888/php-http ^1.1
- owner888/php-mysql ^1.0 (pure-PHP async MySQL driver via
AsyncMysqlPdo; SQLite keeps PDO) - owner888/php-redis ^1.0 (pure-PHP async Redis client;
ext-redisis no longer required)
Application::workerman() always enables Workerman's Fiber event loop (the legacy $fiber opt-out has been removed). On PHP 8.6+, Revolt automatically uses the native Io\Poll driver when none of the uv, ev or event extensions is installed. PHP 8.4 and 8.5 continue to use Revolt's available fallback drivers. HTTP (owner888/php-http), Redis (owner888/php-redis), and MySQL (owner888/php-mysql) all run non-blocking on the Revolt scheduler; SQLite uses local PDO.
HTTP client
Requests::get() / post() / request() keep their existing return-value API. Application::workerman() installs the php-async host Scheduler before workers start; the stateless adapter resolves the current worker's Revolt driver only when used. Socket watchers, timers, DNS and Future callbacks run directly on that driver. No second I/O loop, polling timer or nested Async::run() exists in Workerman. HTTP calls must run inside a worker Fiber, not in the prefork master. A standalone CLI call without Workerman setup uses php-http's original native loop.
TLS verification is mandatory (the former verify_ssl: false setting is rejected). timeout bounds the full request, including redirects and body reads; php-http does not expose an independent connection timeout, so the legacy connect_timeout option currently has no separate effect. Response headers now contain actual response headers in lowercase. Cross-origin redirects drop credentials and other nonstandard headers and do not resend bodies. Multipart uploads are limited to 8 MiB of local files; use application-level chunking for larger files. The Requests facade buffers response bodies; use php-http directly inside a Workerman Fiber for streaming APIs on the same scheduler.
Install
composer require omniphp/framework
Minimal server
<?php // server.php require __DIR__ . '/vendor/autoload.php'; use OmniPHP\Application; use OmniPHP\Http\Kernel; use OmniPHP\Http\Router; use OmniPHP\Http\Context; use OmniPHP\Http\Middlewares\ResponseMiddleware; use Workerman\Worker; Application::boot(__DIR__); // BASE_PATH / CONFIG_PATH / RUNTIME_PATH, .env, timezone, log level, crash handler Application::workerman('server'); // pid/log/stdout under runtime/, Fiber event loop Router::group('/api', function () { Router::get('/hello/{name}', fn(Context $ctx) => ['hello' => $ctx->param('name')]); }, [new ResponseMiddleware()]); $http = new Worker('http://0.0.0.0:8080'); $http->count = 4; $http->onMessage = [Kernel::class, 'handle']; // dispatch → send → access log Worker::runAll();
php server.php start # foreground php server.php start -d # daemon php server.php reload # re-fork workers after a code change
Conventions the framework expects from the application
Application::boot($basePath)runs first in every entry point; it definesBASE_PATH,CONFIG_PATHandRUNTIME_PATH, whichConfig,Logger,LogRotator,FileCacheandViewEnginerequire (they throw if a constant is missing).Lang::init(['lang_dir' => ...])must be given the language directory explicitly (pass it asboot()'slangoption).- Queue job handlers implement
OmniPHP\Queue\HandlerInterfaceand are registered by job name inconfig/queue.phpunderhandlers. - Call
Consumer::consume()once from a dedicated Workerman worker'sonWorkerStart, andConsumer::stop()fromonWorkerStop. Consumption suspends its Fiber in asyncXREADGROUP BLOCKviaowner888/php-redis(zero idle polling, immediate wake-up on new jobs, and immediateAbortSignalcancellation onstop()), while other timers and connections in the same worker keep running. - Application-level hooks are registered at bootstrap rather than discovered:
Logger::registerEngine()for extra log sinks,RedisQueue::setDlqListener()for dead-letter notifications,Router::setExceptionHandler()for error rendering.
Development
composer install
vendor/bin/phpunit # Router / QueryBuilder (SQL only, in-memory SQLite) / Lang
CI runs composer validate, php -l and PHPUnit on PHP 8.4 for every push and tag.
License
MIT — see LICENSE. Query builder guide: docs/database.md.