OmniPHP0.x

Documentation / OmniPHP

Getting started

From an empty directory to a running HTTP service in a few steps.

Requirements

PHP 8.4 or later with OpenSSL, JSON, mbstring and PDO. Composer installs Workerman, Revolt and the framework dependencies.

Install the framework

For an existing application, require the library with Composer.

shell
composer require omniphp/framework

Or create a new project

Use the official skeleton for a ready-made application layout.

shell
composer create-project omniphp/omniphp myapp
cd myapp

Create server.php

For a minimal standalone example, bootstrap the application, register a route and start the Workerman HTTP worker. Save this code as server.php in your Composer project.

php
<?php
require __DIR__ . '/vendor/autoload.php';

use OmniPHP\Application;
use OmniPHP\Http\{Context, Kernel, Router};
use OmniPHP\Http\Middlewares\ResponseMiddleware;
use Workerman\Worker;

Application::boot(__DIR__);
Application::workerman('server');

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'];

Worker::runAll();

Run your server

Start the foreground service and send a request from another terminal. For this example, no database or Redis configuration is required.

shell
php server.php start
# In another terminal:
curl http://localhost:8080/api/hello/OmniPHP
Next guideHTTP & middleware