Distributed & Async PHP Framework

Version 0.4 · GitHub Project · Docs · Issues · Created by Kamil Jamróz

Created for Special Tasks

Kraken is the first and only multi-processed, multi-threaded, fault-tolerant framework for PHP. It has been written to provide easy and reliable API for creating distributed applications using PHP. Kraken aims to solve typical problems of writing such applications and to provide developers with powerful yet elegant tools for dealing with them.

Start writing applications that were previously marked as impossible or hard to implement in PHP right now. Servers, service-oriented architecture, agent-based models, games, complex daemons, socket programs, schedulers and much, much more - nothing is impossible with Kraken!

View Designs

Carefully Designed


Create systems that are asynchronous and concurrent by design.


Divide your application into several containers and run them on multiple threads, processors or hosts.

Fault Tolerant

Write systems that self-heal using remote and local supervision hierarchies.


Modify existing architecture in realtime without need to change in code.

High Performant

Handle up to thousands of connections per second on each container.


Use available options to easily extend and adapt framework features for your needs.

View Features

Fully Featured


The whole architecture of framework is designed to work on top of Event-Loop. This concept allows for asynchronous processing in a simple JavaScript-like manner, that is easy to understand for developers. Behind the abstraction layer the programmer can choose from multiple loop backends to maximize compatibility with different environments.

$loop = new Loop(new SelectLoop);

$loop->onStart(function() {
    echo "Hello World!\n";
$loop->addInterval(1.0, function() {
    echo "Tick!\n";

$emitter = new EventEmitter($loop);

$emitter->once('message', function() {
    echo "Hello!\n";
$emitter->on('message', function($message) {
    echo sprintf("Your message is %s\n", $message);

$emitter->emit('message', 'Kraken is awesome!');


To emit and listen on events the Event-Emitters are used. Each component is built around them allowing architecture to be as loose-coupled and extensible as possible. The framework allows to implement additional modules using either synchronous or asynchronous emitter classes, interfaces and traits to fully cater to various needs.

Promise Support

Managing distributed and dynamic architecture using only event-pattern can become problematic and fault-prone as the project expands. To keep things reliable and rapid the framework ships with its own implementation of Promises/A+ specification. All higher level interfaces shipped with framework use promise-pattern to keep coding easy.

$deferred = new Deferred();
$promise  = $deferred->getPromise();
        function($result) {
            echo sprintf("Result of operation is %s\n", $result);

return $deferred->resolve(new AsyncTask($data));

Asynchronous TCP and UDP sockets

In addition to many modules delivered with framework, one of the most important are the asynchronous TCP and UDP sockets. Developers can use them as pure IPC communication endpoints, build on top of them more advanced controllers for specialized protocols or send and receive data from external services with an easy event-based interface.

$listener = new SocketListener('tcp://', $loop);

$listener->on('connect', function(SocketListenerInterface $listener, SocketInterface $socket) {
    $socket->on('data', function(SocketInterface $socket, $data) {
        $socket->write(new Response($data));
$listener->on('error', function(SocketListenerInterface $listener, $ex) {
    $logger->write(sprintf("Error occurred: %s", $ex->getMessage()));
$reader = new StreamReader($file, $loop);
$writer = new StreamWriter($socket, $loop);


$writer->on('drain', function() {

Asynchronous Stream wrappers

Processing big amount of data is not be possible to be done with reasonable usage of resources without using streams. To deal with this, Kraken provides various asynchronous and synchronous stream controllers. Writers, Readers, Seekers, Duplex streams, pipes and more complex interfaces are provided.

Standalone HTTP & WebSocket server

The most popular Web protocols, HTTP and Websockets, are supported through a standalone server. Framework is able to handle requests and produce asynchronous responses for them and its sub-protocols. In addition firewalls, routers, session-saving mechanisms and protocol encoders are featured.

$server = new NetworkServer(
    new SocketListener('tcp://', $loop)

$server->addRoute('/', new IndexController);
$server->addRoute('/about', new AboutController);
$server->addRoute('/{first}/{second}', new FallbackController);
$server->addRoute('/chat', new WsServer(null, new ChatApp));

Consitent Multi-processing & Multi-threading

Writing multi-processed and multi-threaded applications is supported and simplified with a simple and consistent interface. Developer do not longer need to think about forking and creating php threads manually or how to store and clean them. Everything is done automatically using several fallback layers and keeps to work independently.

Processes & Threads as Containers

Distributed processing between active processes and threads is designed to work as actor-based distribution models do. Processes and threads extends common container class and are treated as separate actors. Each actor can work independently or in cluster. Thanks to shared interface operating on containers does not require from architect to remember which of them are processes and threads.

Message-driven Communication

To make utterly perfect MT programs developers don't need mutexes, locks, or any other form of inter-thread communication except messages sent across endpoints. With this idea in mind, the whole concept of exchanging information between contaiers is purely message-driven. Framework, by default, ships with several different IPC that programmer can use individually or all-together.

Configurable Supervision Hierarchies

To ensure system reliability, each one of containers is equipped with configurable supervisor systems. These allow developers to define and inject strategies defining how to react to thrown errors and exceptions. Access to both local and remote supervisors makes possible to deal with them locally or delegate decision-handling to one of the parents.

$local = $runtime->getSupervisor();

    'App\Exception\SomeCustomException' => [ 'Log', 'ContainerContinue' ],
    'App\Exception\OtherException'      => [ 'RuntimeRecreate' ],
    'Kraken\Throwable\Error\FatalError' => [ 'Log', 'ContainerDestroy' ],
    'Exception' => [ 'Log', 'ContainerContinue' ],
    'Error'     => [ 'Log', 'ContainerContinue' ]
$router = $channel->getBus('slave')->getInput();
    new RuleMatchDestination($channel->getName()),
    new RuleHandler(function($params) { // Do something with message })
    new RuleHandler(function($params) use($channel) {
        $channel->getBus('master')->push($channel->getParent(), $params['protocol'], $params['flags']);

Built-in Routing System

All communication between containers is enclosed to special controllers called Channels. They provide single abstract interface to exchange data, regardless of IPC model chosen to do the job. Each one consists of configurable routers, message & protocol encoders and IPC abstraction layer. Define the way of passing messages once, make it adaptive and see how easy sending and receiving messages gets.

Extensible Console Clients & Servers

Aside from code manipulation the framework support parsing messages received through command line. Use console clients to execute predefined tasks, change state and structure of working architecture without need to restart everything. Write your own commands to extend its effect to your business logic. Use console servers to be able to divide your architecture to multiple hosts easily and manage all of them from single place.

PHP 5.5+ & PHP 7.0+ Compatible

Code has been written in PHP 5.5+ and PHP 7.0+ in mind. It is fully compatible and tested on both of them.

React Compatible

By default framework ships with React adapters to make its components usable. Any of React core or based-on modules is able to work perfectly in Kraken environment.

Platform Independent

All required to work mechanics including managing processes and threads is written in a platform-independent way to allow framework to be run on both Unix and Windows operating systems.

Show Performance Data

Extremely Fast

Able to emit millions of events per second

Able to handle tens of thousands of messages and promises per second

Several times faster than traditional PHP approach

Amount of [ HTTP Req-Reps / s ]
  • Kraken 0.2
  • Express
  • Phalcon 1.3
  • Slim 2.6
  • CodeIgniter 3
  • Yii 2.0
  • Bear 1.0
  • Silex 1.2
  • Fuel 1.8
  • Symfony 2.6
  • Cake 3.0
  • 6198
  • 4884
  • 3953
  • 1946
  • 1771
  • 932
  • 869
  • 860
  • 759
  • 654
  • 622

Scalable for multiple processes and threads

Able to extend over 100% performance under pressure for limited amount of time

Faster than standard libraries running on Node.js

Amount of [ HTTP Req-Reps / s ]
  • Kraken 0.2
  • Node.js + Express
  • 6198
  • 4884
Amount of [ WebSocket Emits / s ]
  • Kraken 0.2
  • Node.js + SockJS
  • 64613
  • 55944
Show Miscellaneous

Bound to Amaze

Start writing asynchronous, multi-processed, multi-threaded application in PHP right now and be amazed how easy the whole process gets thanks to Kraken Interface. Try it now for free.

Still have some questions? Visit one of our pages of interest listed below or ask the community.

Start from the Beginning

Everything is possible. The impossible just takes longer.