Search by

omniphp / framework

owner888

OmniPHP — The universal PHP framework. Lightweight, Workerman-based: HTTP router & middleware, query builder & migrations, Redis Stream queue, template engine, cache, i18n and structured logging.

Package info

github.com/owner888/omniphp

pkg:composer/omniphp/framework

Statistics

Installs: 13

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.0 2026-09-30 08:52 UTC

This package is auto-updated.

Last update: 2026-09-30 08:52:55 UTC


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.x releases.

What's inside

Namespace Purpose
OmniPHP\Application / CrashHandler One-call bootstrap (paths, .env, timezone, log level, i18n) and a three-tier fatal/uncaught handler for long-running processes
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\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 Minimal cURL HTTP client, 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-curl, ext-json, ext-mbstring, ext-pdo
  • ext-redis (for the Redis cache driver, the queue and the rate limiter)
  • workerman/workerman ^5.1

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 defines BASE_PATH, CONFIG_PATH and RUNTIME_PATH, which Config, Logger, LogRotator, FileCache and ViewEngine require (they throw if a constant is missing).
  • Lang::init(['lang_dir' => ...]) must be given the language directory explicitly (pass it as boot()'s lang option).
  • Queue job handlers implement OmniPHP\Queue\HandlerInterface and are registered by job name in config/queue.php under handlers.
  • 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.

License

MIT — see LICENSE. Query builder guide: docs/database.md.