-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Oktaax is an OpenSwoole-based framework designed for building high-performance PHP applications. It offers a lightweight, developer-friendly alternative to traditional frameworks by taking full advantage of OpenSwoole's coroutine capabilities. Whether you're building an HTTP server, WebSocket server, or running Laravel applications, Oktaax makes it easier and faster.
- PHP 8.1+
- OpenSwoole PHP extension
(Note: OpenSwoole does not support PHP 8.4 yet.)
composer install jefyokta/oktaax
You can run your laravel application with oktaax as octane alternative. compatible with: laravel 10+
<?php
$app = new class extends Oktaax {
use Laravelable;
};
$app->registerLaravel(new Laravel('path/to/laravel/project'));
$app->listen(80, '127.0.0.1');
Build an HTTP server using familiar and expressive syntax:
<?php
$app = new Oktaax;
$app
->get("/", fn($request, $response) => $response->end("Welcome to Oktaax"))
->get("/user/{username}", function ($request, $response) {
$user = $request->params['username'];
$response->end("Hello, {$user}");
})
->post("/user", function ($request, $response) {
$data = $request->post;
$response->end("User created with data: " . json_encode($data));
})
->put("/user/{id}", function ($request, $response) {
$id = $request->params['id'];
$response->end("User {$id} updated");
})
->delete("/user/{id}", function ($request, $response) {
$id = $request->params['id'];
$response->end("User {$id} deleted");
});
$app->listen(3000);
Oktaax supports Blade, the default Laravel template engine. Configuration for Blade is already set up, but you can customize it to suit your needs.
<?php
$app = new Oktaax;
$app->blade(new BladeConfig(
viewDir: "views/",
cacheDir: "views/cache",
functionDir: "mybladefunction.php"
));
use Oktaax\Http\Request;
use Oktaax\Http\Response;
$app->post("/user",function(Request $request, Response $response)
{
[$data,$err] = $request->validate(['name'=>'required|max:100','email'=>'required|email','password'=>'required|min:8')->getAll();
if(null !== $err){
//handle error here
}
User::create($data);
$response->end('ok');
}
Oktaax makes it simple to build WebSocket servers with OpenSwoole. Define WebSocket event handlers using intuitive methods:
<?php
use Oktaax\Oktaax;
use Oktaax\Websocket\HasWebsocket;
use Oktaax\Http\Request;
use Oktaax\Http\Response;
use Oktaax\Websocket\Client;
use Oktaax\Websocket\Server;
$app = new class extends Oktaax {
use HasWebsocket;
};
$app->get("/user", function (Request $request, Response $response) {
$response->end("User endpoint hit!");
});
$app->ws('welcome', function (Server $server, Client $client) {
$server->reply($client, "Hi Client {$client->fd}");
});
$app->listen(3000);
<?php
use Oktaax\Interfaces\Channel;
use Oktaax\Websocket\Client;
class EvenChannel implements Channel
{
public function eligable(Client $client): bool
{
return $client->fd % 2 === 0;
}
}
<?php
$app->ws('even', function (Server $server, Client $client) {
$server->toChannel(EvenChannel::class)->broadcast(function ($client) {
return "Hello {$client->fd}! You have an even fd!";
});
});