Search by

jefyokta / oktaax

jefyokta

HTTP and WebSocket server library for Swoole

Package info

github.com/jefyokta/oktaax

pkg:composer/jefyokta/oktaax

Statistics

Installs: 95

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v4.0.0-beta 2026-02-28 02:26 UTC

README

Build HTTP APIs, streamed responses, SSE, background tasks, and WebSocket services with PHP and Swoole. Each application owns its configuration, router, services, and lifecycle scopes.

Start here: User guide · Runnable examples · API reference · Migration

Requirements

  • PHP 8.3+ with the swoole extension loaded in the CLI.
  • Composer. The repository's development dependencies require PHP 8.4+.
  • A terminal: Oktaax runs its own server, rather than PHP-FPM or php -S.
composer require jefyokta/oktaax
php --ri swoole

The documentation describes the current source tree. For an existing project, check the migration guide: compatibility namespaces have been removed.

Your first server

Create server.php beside your application's vendor/ directory:

<?php

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

use Oktaax\Http\Request;
use Oktaax\Http\Response;
use Oktaax\Oktaax;

$app = new Oktaax();
$app->get('/health', fn() => ['ok' => true]);
$app->get(
    '/users/{id:\d+}',
    fn(Request $request) => [
        'id' => $request->param('id'),
    ],
);
$app->post('/users', function (Request $request, Response $response) {
    $user = $request->validate(['name' => 'required|string']);
    $response->status(201)->json($user);
});
$app->listen(3000, '127.0.0.1');
php server.php

In another terminal:

curl http://127.0.0.1:3000/health
curl -i -X POST http://127.0.0.1:3000/users \
  -H 'Content-Type: application/json' -d '{"name":"Ada"}'

The first request returns {"ok":true}. The second returns HTTP 201 and {"name":"Ada"}. A missing name returns HTTP 422. Stop the server with Ctrl+C.

Learn by topic

Topic Guide Example recipe
Installation and application layout Getting started http
Routes, middleware, authentication boundaries, CSRF Routing http, csrf
Input sources, JSON, uploads, validation Requests http
JSON, templates, files, custom results, Inertia Responses responses, inertia
Application, worker, request, and connection scopes Lifecycle and services lifecycle
Database models and transactions Database and Eloquent database, mysql
Streaming and connection cleanup Streaming and SSE sse
Task workers, events, IPC, timers Tasks and events tasks, events
JSON packets and browser client WebSocket websocket
Coroutine HTTP requests and body handling HTTP client http-client
Error pages, debug mode, custom templates and handlers Error handling errors
Configuration, runtimes, deployment Configuration and operations all recipes
Testing, checks, troubleshooting Testing all recipes

From a checkout of this repository:

composer install
php examples/guide/serve.php http
# Try the redesigned error pages:
OKTAAX_DEBUG=1 php examples/guide/serve.php errors

Run one server at a time, or set OKTAAX_PORT to use another port. See examples/README.md for commands and expected output.

Development

Formatting uses Node.js/npm with Prettier and its PHP plugin:

npm ci
npm run format
npm run format:check
composer test
composer analyse -- --debug
composer test:integration

Integration tests start local servers and require loopback sockets and child processes. They exercise the actual example factories as well as the runtime kernel. See testing and the architecture guide.