GithubHelp home page GithubHelp logo

kraken-php / framework Goto Github PK

View Code? Open in Web Editor NEW
1.1K 86.0 58.0 1.58 MB

Asynchronous & Fault-tolerant PHP Framework for Distributed Applications.

Home Page: http://kraken-php.com

License: MIT License

PHP 99.61% Shell 0.39%
php asynchronous fault-tolerance supervision async-library multi-process multi-thread async stream microservices

framework's Introduction

Kraken PHP Framework ~ Release the Kraken!

Build Status Latest Stable Version Latest Unstable Version License Gitter @kraken_php on Twitter

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.


Description

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!

Feature Highlights

Kraken features:

  • 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.

Performance

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 similar amount of connections as Node.js.

Note: Keep in mind that Kraken project does not solely focus around HTTP performance. It provides a set of distinct asynchronous libraries to use in PHP. The attached graph's main intention is to show that PHP is fast enough to compete with the leading technologies available on the market. The HTTP component has been chosen as it is the only one that can be easily compared between asynchronous and synchronous MVC frameworks. Do not treat it as an actual benchmark.

Powered By

Kraken Framework is built on top of asynchronous library named Dazzle Project. If you are looking for a solution simpler than framework, you might consider using it instead.


Requirements

  • PHP-5.6 or PHP-7.0+,
  • UNIX or Windows OS,
  • Additional constraints based on which components you do plan to use.

Installation and Official Documentation

Documentation for the framework can be found in the official documentation page. To see installation instructions, please check out application skeleton or go to installation guide.

Examples

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

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.


If there are any additional questions that you have about framework, please check whether the answers for them have been already posted in issues or ask on our gitter room.

Contributing

Thank you for considering contributing to Kraken Framework! The contribution guide can be found in the contribution tips.

License

Kraken Framework is open-sourced software licensed under the MIT license. The documentation is provided under FDL-1.3 license.

framework's People

Contributors

hidehalo avatar khelle avatar okonomiyaki3000 avatar optiman avatar pborreli avatar radarhere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

framework's Issues

The console problems and fixes

At the moment the console server is bugged. Sometimes it stops working and needs restart to fix the most common problems, but sometimes the message routing fails or it does not clean after itself.

Right now, the best solution for this problem is not to use console, but stick to alternative start method, which in default configuration is:

$> php ./data/autorun/kraken.process undefined Main Main

This is the logic that works underneath project:create command and it is equal in use. If there are any subprocesses or subthreads in Main, they will also be fired. The only con of this approach is, that you will not be able to use console command, therefore when shuting down the project you will need to kill all processes manually.

This is very urgent problem, and should be prioritized to be done for the release of v0.4

Kraken project:create throws an exception

I executed the following:

as a root:

> composer create-project --prefer-dist kraken-php/kraken .
> php kraken.server
> php kraken server:ping 
> php kraken project:create

the last command throws this:

Executing : project:create ... failure!
Response  : "fwrite(): send of 159 bytes failed with errno=32 Broken pipe" in /home/vagrant/github/epp-client/vendor/kraken-php/util/Isolate/Isolate.php:73
Reason    : Kraken\Throwable\Error\NoticeError

PHP 5.6.17 (cli) (built: Jan 9 2016 10:31:18)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

Note that the following command works fine:

> php ./data/autorun/kraken.process undefined Main Main

Your help is appreciated. Thanks.

Implement Scheduler

It should be possible to create Timers that requirse passing explicit datetime when they have to fire instead of intervals.

PHP Warning: Uncaught Throwable trace:

Composer version 1.2.1 2016-09-12 11:27:19

PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies

composer create-project --prefer-dist kraken-php/kraken .
Installing kraken-php/kraken (v0.3.1)
  - Installing kraken-php/kraken (v0.3.1)
    Loading from cache

Created project in .
> php ./data/script/script.install
string(4) "hej?"
Loading composer repositories with package information
Updating dependencies (including require-dev)
............
............
............
Package guzzle/common is abandoned, you should avoid using it. Use guzzle/guzzle instead.
Package guzzle/stream is abandoned, you should avoid using it. Use guzzle/guzzle instead.
Package guzzle/parser is abandoned, you should avoid using it. Use guzzle/guzzle instead.
Package guzzle/http is abandoned, you should avoid using it. Use guzzle/guzzle instead.
Writing lock file
Generating autoload files
>composer create-project --prefer-dist kraken-php/kraken .
>chmod 777 -R data/log/ data/storage/
>php kraken.server 
Server is booting...
PHP Warning:  Uncaught  Throwable trace:
         0. [WarningError] "require(): data:/ wrapper is disabled in the server configuration by allow_url_include=0" in /ConfigFactory.php:48
        Stack trace:
         0. [throwable] Kraken\Throwable\Error\WarningError(...) in ErrorHandler:63
         1. [call] Kraken\Throwable\ErrorHandler::handleError(2, ""require(): data:// wrapper is d...", "/home/absiddique/Projects/php/kk...", 48, Array) in ConfigFactory:48
         2. [call] Undefinedrequire() in ConfigFactory:48
         3. [call] Kraken\Config\ConfigFactory->Kraken\Config\{closure}() in unknown:0
         4. [call] Undefinedcall_user_func_array(Closure, Array) in SimpleFactoryTrait:128
         5. [call] Kraken\Util\Factory\SimpleFactory->create() in ConfigProvider:180
         6. [call] Kraken\Root\Provider\ConfigProvider->createConfig("/home/absiddique/Projects/php/kk...") in ConfigProvider:239
         7. [call] Kraken\Root\Provider\ConfigProvider->configure(Kraken\Config\Config) in ConfigProvider:103
         8. [call] Kraken\Root\Provider\ConfigProvider->register(Kraken\Root\Console\Server in /home/absiddique/Projects/php/kk/vendor/kraken-php/throwable/ErrorHandler.php on line 63
PHP Fatal error:  Kraken\Config\ConfigFactory::Kraken\Config\{closure}(): Failed opening required 'data://text/plain;base64,PD9waHAKCi8qKgogKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KICogRGVmYXVsdCBjb25maWd1cmF0aW9uIGZvciBDb25zb2xlIFNlcnZlci4KICoKICogRm9yIG1vcmUgaW5mb3JtYXRpb24gdmlzaXQ6IGh0dHA6Ly9rcmFrZW4tcGhwLmNvbS9kb2NzCiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQogKi8KcmV0dXJuIFsKICAgIC8qKgogICAgICogLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KICAgICAqIEFkZGl0aW9uYWwgY29uZmlndXJhdGlvbiBmaWxlIHRvIGxvYWQuCiAgICAgKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQogICAgICogVGhpcyB2YXJpYWJsZS in /home/absiddique/Projects/php/kk/vendor/kraken-php/config/ConfigFactory.php on line 48
        Throwable trace:
         0. [FatalError] "Kraken\Config\ConfigFactory::Kraken\Config\{closure}(): Failed opening required 'data:/plain;base64,PD9waHAKCi8qKgogKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KICogRGVmYXVsdCBjb25maWd1cmF0aW9uIGZvciBDb25zb2xlIFNlcnZlci4KICoKICogRm9yIG1vcmUgaW5mb3JtYXRpb24gdmlzaXQ6IGh0dHA6Ly9rcmFrZW4tcGhwLmNvbS9kb2NzCiAqIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQogKi8KcmV0dXJuIFsKICAgIC8qKgogICAgICogLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KICAgICAqIEFkZGl0aW9uYWwgY29uZmlndXJhdGlvbiBmaWxlIHRvIGxvYWQuCiAgICAgKiAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQogICAgICogVGhpcyB2YXJpYWJsZS" in /ConfigFactory.php:48
        Stack trace:
         0. [throwable] Kraken\Throwable\Error\FatalError(...) in ErrorHandler:64
         1. [call] Kraken\Throwable\ErrorHandler::handleError(64, ""Kraken\Config\ConfigFactory::Kr...", "/home/absiddique/Projects/php/kk...", 48) in ErrorHandler:80
         2. [call] Kraken\Throwable\ErrorHandler::handleShutdown(1) in EnvironmentProvider:45
         3. [call] Kraken\Root\Provider\EnvironmentProvider->Kraken\Root\Provider\{closure}() in unknown:0
         4. [main]
Killed

Make current Filesystem a Cloud-based one and add new async one

At first Filesystem was added only for the need of reading and writing configuration files. Then, the additional abstracitons were added, because they were easy to implement on top of league's filesystem. There is set of drawbacks of using this apporach and would be beneficial to reimplement it. The proposal is:

  • Move current Filesystem (Kraken\Filesystem) to Cloud (Kraken\Cloud) namespace.
  • Implement async Filesystem in empty (Kraken\Filesystem).

Logging does not work with threads

Logging does not work with threads. This happens because Pthreads extension does not copy static arrays accross thread instances. Monolog which is used unnderneath Kraken\Log keep its error levels in static array.

Create FilesystemFactory

Kraken already posses FilesystemAdapterFactory class which has definition for creating all filesystem adapters. This adapter is then injected into newly created instance of Filesystem. It would be useful to automatize this further and create FilesystemFactory which, using the same interface, would be able to create instances of filesystem which already injected proper adapter.

Add sendCommand method to runtime managers

Currently runtime managers allow sending asynchronous messages and requests using their interface. It would be useful to allow invoking remote commands the same way.

Where is the Performance Benchmark Code?

Hey, my questions is obivious. I'm curious what kind of stuff and which conditions you tested in. There is only image that shows how good kraken in but how? In what conditions, I think its important too.

Benchmark source code?

I'm curious about performance. I'm also developing framework that can work as HTTP server and as WebSockets server, but typical https://github.com/kenjis/php-framework-benchmark doesn't support such configurations.
It also seems that you compare to other frameworks that are not running under something like ReactPHP (which some of them are capable of).

Would you like to share your setup and benchmark source code? Didn't found it in this repo, in other repos of organization and on the website.

Async stream readers should not start reading automatically

Right now all asynchronous streams start reading automatically. It is useful in network-based streams, but undesirable behaviour for file-based ones. Also, it contradicts with asynchronous write bahviour, which starts looping only after the first write and may create perforance issues on larger number of streams.

Make supervision-related solvers names more meaningful

Right now there are to solvers for migrating problem solving between local and remote superivision systems:

CmdEscalateManager
CmdEscalateSupervisor

Using them however might be hard to differentiate. The new proposed naming, better describing what the really to should be:

CmdEscalateManager    --> CmdEscalate
CmdEscalateSupervisor --> CmdSolve

Make delay(), delayOnce() and delayTimes() methods in Event\EventEmtiter API more efficient

Current implementation of EventEmitters ::delay() method is slow due to usage of call_user_func_array() and func_get_args() functions. It might be faster with implementation of CallableProxy() that is able to switch its underneath function dynamically.

Proposition - change delay methods to follow this code:

$counter = 0;
$proxy = new CallableProxy();
$proxy->setMethodToInvoke(function() use($proxy, &$counter, $ticks, $listener) {
    if (++$counter === $ticks)
    {
        unset($counter);
        $proxy->setMethodToInvoke($listener);       
    }
});
return $this->on($event, $ticks, $proxy);

Failed container doesn't care what instructions it gets and from

When container fails and escalates the problem to its parent supervision system, it doesn't care what instructions it get and from. It makes it accept instructions that might not be connected to solving the issue. What's more it allows executing the commands that should not be allowed in failed state.

Add (Runtime|Process|Thread)Manager::knows(Runtime|Process|Thread) methods

Method (Runtime|Process|Thread)Manager::exists(Runtime|Process|Thread) returns false for Remote managers. This is desired behaviour since it allows Routing mechanisms to know if given container is neighbour of current or not. However, there are cases that we would like to know if container exists anywhere, so additional method should be added.

Change the name of EventHandler class

In theory, event-driven architecture uses sets of event emitters and event listeners to communicate using events. Kraken official documenatation refers to these two types of objects the same. However, in implementation there is EventEmitter and - misleadingly - EventHandler. Therefore, EventHandler should be renamed to EventListener to keep implementation consistent to documentation and as near as possible to theoretical implementation.

Error starting server with kraken.server

hi,
i have a ready project kraken with composer
"composer create-project --prefer-dist kraken-php/kraken"
but when starting server "kraken.server" i get error "kraken.server: command not found"

how to fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.