Kraken PHP Framework ~ Release the Kraken!
Note: This repository contains the core of the Kraken Framework. If you want to start developing new application with Kraken, check out Kraken Application Skeleton. If you want to learn more visit official website.
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.
The main focus of Kraken Framework is put on:
- Concurrency : create systems that are asynchronous and concurrent by design,
- Distribution : divide your application into several containers and run them on multiple threads, processors or hosts,
- Fault tolerance : write systems that self-heal using remote and local supervision hierarchies,
- Elasticity : modify existing architecture in realtime without need to change in code,
- High performance : handle up to thousands of connections per second on each container,
- Extensibility : use available options to easily extend and adapt framework features for your needs.
Start writing applications that were previously marked as impossible or hard to implement in PHP right know. Servers, service-oriented architecture, agent-based models, games, complex daemons, socket programs, schedulers and much, much more - nothing is impossible with Kraken!
- Support for asynchronous programming using fully-featured event Loop with multiple backgrounds.
- Support for event-driven architecture.
- Easy to understand and work with Promise-based API.
- Consistent multi-processing and multi-threading.
- Process and Thread abstraction as isolated message-driven containers.
- Built-in message routing system and IPC abstraction.
- Configurable local and remote supervision hierarchies.
- Centralized deployment and management.
- Extensible Console and Server interface.
- Asynchronous TCP and UDP sockets.
- Asynchronous Stream wrappers.
- Standalone HTTP and WebSocket server.
- Variety of IPC models.
- ReactPHP-compatibility adapters.
- ...and more.
Full list of features can be found on official website.
Kraken Framework is fully modular and each of its components can be used separately. If for some reason you don't want to download full application stack, you can require any of the following components:
- Kraken/Channel : IPC abstractions,
- Kraken/Config : Default configurator,
- Kraken/Console : Console and Server implementation,
- Kraken/Container : Service container,
- Kraken/Core : Framework core,
- Kraken/Environment : Environment controller,
- Kraken/Event : Support for events,
- Kraken/Filesystem : Default filesystem,
- Kraken/Ipc : IPC models,
- Kraken/Log : Default logger,
- Kraken/Loop : Event-loop implementation,
- Kraken/Network : Network protocols servers,
- Kraken/Promise : Promise/A+ implementation,
- Kraken/Root : Default composition root,
- Kraken/Runtime : Process and Thread abstractions,
- Kraken/Stream : Stream wrappers,
- Kraken/Supervision : Supervisors and problem solvers,
- Kraken/Test : Test helpers,
- Kraken/Throwable : Throwable hierarchy,
- Kraken/Util : Utility classes and methods.
Kraken is able to emit millions of events and thousands of messages and connections per second using single container. It is scalable for multiple processes and threads, faster than traditional PHP approach and able to handle same or higher amount of connections that Node.js.
- PHP-5.5, PHP-5.6 or PHP-7.0+,
- Pthreads extension enabled (only if you want to use threading),
- UNIX OS.
Installation and Official Documentation
There are few examples you can try, before deciding to use Kraken:
If you have written your own demo application for Kraken, and want to list it here, contact us!
Frequently Asked Questions
Is Kraken a framework or a set of libraries?
Kraken is both. It gives developer a fully working and pre-configured framework to start writing asynchronous applications easily, but at the same moment it provides a set of independent modules. The choice is up to developer whether he wants to use the full application stack, or build something different using only selected components.
How does the Kraken differ from other PHP async libraries?
In comparison to already existing PHP async libraries, Kraken gives the developer not only the async tools, but also do the most of the dirty work of creating distributed applications. It gives you consistent interface for working with processes and threads, implements fault-tolerance mechanisms, allows usage of remote and local supervision hierarchies, gives IPC abstractions and implements most important messaging patterns such as routing, heartbeating and much, much more. Instead of thinking how to use async libraries in the new project and how to design the project with them, developer can simply start Kraken instance and focus on its business logic!
Is PHP GC able to handle daemonized, long-running application?
In most cases yes, but developers still have to keep an eye on application memory usage. PHP 5.5+, which is required for using framework, is able to successfully deal with proper memory handling and garbage collecting. It proves to be true regarding Kraken modules as in development cycle special attention was paid to ensure they do not leak memory. This, however, cannot be guaranteed with usage of third party vendors as some (ex. ORMs) are known to be prone to this problem. The easiest way to avoid it is to simply use destructors, unset functions and create memory allocation and deallocation tests. If despite that you still stumble across this problem, the best way to deal with it is to isolate leaking piece of code in separated container and restart it cyclically when it reaches its memory limits.
Thank you for considering contributing to Kraken Framework! The contribution guide can be found in the contribution tips.