Skip to main content

Neutomic

build fast, run faster.

Neutomic is a blazing fast asynchronous framework designed for building high-performance PHP applications. Its non-blocking architecture and integrated toolset deliver exceptional speed and efficiency, making it ideal for demanding web applications.

composer create-project neutomic/skeleton:dev-main my-project
Logo
src/Handler/IndexHandler.php
<?php

declare(strict_types=1);

namespace App\Handler;

use Neu\Component\Http\Message\Method;
use Neu\Component\Http\Message\RequestInterface;
use Neu\Component\Http\Message\ResponseInterface;
use Neu\Component\Http\Message\Response;
use Neu\Component\Http\Router\Route\Route;
use Neu\Component\Http\Runtime\Context;
use Neu\Component\Http\Runtime\Handler\HandlerInterface;

#[Route(name: 'index', path: '/', methods: [Method::Get])]
final readonly class IndexHandler implements HandlerInterface
{
public function handle(Context $context, RequestInterface $request): ResponseInterface
{
return Response\text('Hello, World!');
}
}

Hello World

Neutomic makes it easy to build web applications with PHP.

It is a modern, lightweight, and high-performance framework that is designed to help you focus on what matters most: your application.

A Modern Database Abstraction Layer

Neutomic provides a powerful and intuitive database abstraction layer that simplifies interaction with your database.

Built on top of amphp/sql, amphp/postgres, and amphp/mysql, Neutomic offers a performant and scalable solution for managing your database operations.

By leveraging Neutomic's database components, you can build complex queries with ease, ensuring your application remains maintainable and scalable.

Whether you're performing simple queries or intricate data manipulations, Neutomic's database abstraction layer handles the heavy lifting, allowing you to focus on developing your application's core functionality.

src/Handler/Article/IndexHandler.php
<?php

declare(strict_types=1);

namespace AppHandlerArticle;

use NeuComponentDatabaseDatabaseInterface;
use NeuComponentHttpMessageMethod;
use NeuComponentHttpMessageRequestInterface;
use NeuComponentHttpMessageResponseInterface;
use NeuComponentHttpMessageResponse;
use NeuComponentHttpRouterRouteRoute;
use NeuComponentHttpRuntimeContext;
use NeuComponentHttpRuntimeHandlerHandlerInterface;

#[Route(name: 'article:index', path: '/article', methods: [Method::Get])]
final readonly class IndexHandler implements HandlerInterface
{
public function __construct(
private DatabaseInterface $database,
) {}

public function handle(Context $context, RequestInterface $request): ResponseInterface
{
$query = $this->database->createQueryBuilder();
$expression = $this->database->createExpressionBuilder();

$articles = $query
->select('*')
->from('articles', 'a')
->where(
$expression->equal('a.published', ':published'),
)
->fetchAllAssociative([
'published' => true,
])
;

return Responsejson([
'articles' => $articles,
]);
}
}
➜ ab -n100000 -c100 -k http://localhost:8080/

...

Concurrency Level: 100
Time taken for tests: 1.452 seconds
Complete requests: 100000
Failed requests: 0
Keep-Alive requests: 100000
Total transferred: 72600000 bytes
HTML transferred: 47600000 bytes
Requests per second: 68869.81 [#/sec] (mean)
Time per request: 1.452 [ms] (mean)
Time per request: 0.015 [ms] (mean, across all concurrent requests)
Transfer rate: 48827.62 [Kbytes/sec] received
info

The benchmark was performed against neutomic/skeleton project, running on Macbook Pro M1, using PHP 8.3, in production mode.

Blazing Fast Performance

Neutomic's server is built on top of the amphp/http-server and amphp/cluster, making it capable of handling tens of thousands of HTTP requests per second.

In this benchmark, the server demonstrates its impressive performance, achieving nearly 69,000 requests per second with zero failed requests.

Neutomic ensures that your applications can handle high traffic efficiently, providing a robust foundation for any web application.

Server-Sent Events

Neutomic makes it easy to build real-time web applications with PHP using Server-Sent Events (SSE).

Server-Sent Events allow the server to push real-time updates to the client over a single HTTP connection. This is particularly useful for applications that require live updates such as notifications, real-time charts, or live feeds.

example.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Server-Sent Events Example</title>
</head>
<body>
<div>
<h1>Server-Sent Events</h1>
<div id="events"></div>
</div>

<script>
const eventSource = new EventSource('/sse');
const eventsContainer = document.getElementById('events');

eventSource.addEventListener('message', (event) => {
const messageElement = document.createElement('p');
messageElement.innerText = event.data;

eventsContainer.appendChild(messageElement);
});
</script>
</body>
</html>
src/Handler/ServerSentEventsHandler.php
<?php

declare(strict_types=1);

namespace App\Handler;

use Neu\Component\Http\Message\Method;
use Neu\Component\Http\Message\RequestInterface;
use Neu\Component\Http\Message\ResponseInterface;
use Neu\Component\Http\Message\Response;
use Neu\Component\Http\Router\Route\Route;
use Neu\Component\Http\Runtime\Context;
use Neu\Component\Http\Runtime\Handler\HandlerInterface;
use Neu\Component\Http\ServerSentEvent;
use Psl\Async;

#[Route(name: 'server-sent-events', path: '/sse', methods: [Method::Get])]
final readonly class ServerSentEventsHandler implements HandlerInterface
{
public function handle(Context $context, RequestInterface $request): ResponseInterface
{
$stream = ServerSentEvent\EventStream::forContext($context);

Async\run(static function () use ($stream): void {
while (true) {
if ($stream->isClosed()) {
break;
}

$stream->send(new ServerSentEvent\Event(
type: 'message',
data: 'Hello, World!',
));

Async\sleep(1);
}
})->ignore();

return $stream->getResponse();
}
}