-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 944a2b5
Showing
36 changed files
with
2,113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
vendor/ | ||
composer.lock | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Kraken Demo Application | ||
|
||
[![Build Status](https://travis-ci.org/kraken-php/framework.svg)](https://travis-ci.org/kraken-php/framework) | ||
[![Total Downloads](https://poser.pugx.org/kraken-php/kraken/downloads)](https://packagist.org/packages/kraken-php/kraken) | ||
[![Latest Stable Version](https://poser.pugx.org/kraken-php/framework/v/stable)](https://packagist.org/packages/kraken-php/framework) | ||
[![Latest Unstable Version](https://poser.pugx.org/kraken-php/framework/v/unstable)](https://packagist.org/packages/kraken-php/framework) | ||
[![License](https://poser.pugx.org/kraken-php/framework/license)](https://packagist.org/packages/kraken-php/framework) | ||
|
||
> **Note:** This repository contains pre-configured application for fast creation of new projects with [Kraken Framework](https://github.com/kraken-php/framework). | ||
<br> | ||
<p align="center"> | ||
<img src="https://avatars2.githubusercontent.com/u/15938282?v=3&s=150" /> | ||
</p> | ||
|
||
## 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, | ||
* __Faul 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! | ||
|
||
For more information go to [framework repository](https://github.com/kraken-php/framework) or [official website](http://kraken-php.com). | ||
|
||
## Requirements | ||
|
||
* PHP-5.5, PHP-5.6 or PHP-7.0+, | ||
* [Pthreads](http://php.net/manual/en/book.pthreads.php) extension enabled (only if you want to use threading), | ||
* UNIX or ~~Windows~~ OS. | ||
|
||
## Installation and Official Documentation | ||
|
||
To install this pre-configured application, please go to desired location to store project, then call composer: | ||
|
||
``` | ||
composer create-project --prefer-dist kraken-php/kraken . | ||
``` | ||
|
||
Documentation for the framework can be found in the [official documentation][2] page. | ||
|
||
## Contributing | ||
|
||
This library is pre-configured project application for Kraken Framework. To make contributions, please go to [framework repository][3]. | ||
|
||
## License | ||
|
||
Kraken Framework is open-sourced software licensed under the [MIT license][6]. The documentation is provided under [FDL-1.3 license][7]. | ||
|
||
[1]: http://kraken-php.com | ||
[2]: http://kraken-php.com/docs | ||
[3]: http://kraken-php.com/getting_started | ||
[4]: http://kraken-php.com/faq | ||
[5]: http://kraken-php.com/docs/contributions | ||
[6]: http://opensource.org/licenses/MIT | ||
[7]: https://www.gnu.org/licenses/fdl-1.3.en.html | ||
[8]: https://groups.google.com/forum/#!forum/kraken-php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Container\Test; | ||
|
||
use Kraken\Core\CoreInterface; | ||
use Kraken\Runtime\RuntimeContainer; | ||
use Kraken\Runtime\RuntimeContainerInterface; | ||
|
||
class TestContainer extends RuntimeContainer implements RuntimeContainerInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $endpoint = 'tcp://%localhost%:2080'; | ||
|
||
/** | ||
* @override | ||
* @inheritDoc | ||
*/ | ||
public function genEndpoint() | ||
{ | ||
return $this->endpoint; | ||
} | ||
|
||
/** | ||
* @override | ||
* @inheritDoc | ||
*/ | ||
protected function config(CoreInterface $core) | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @override | ||
* @inheritDoc | ||
*/ | ||
protected function boot(CoreInterface $core) | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* @override | ||
* @inheritDoc | ||
*/ | ||
protected function construct(CoreInterface $core) | ||
{ | ||
$this->onCreate(function() { | ||
$this->onCreateHandler(); | ||
}); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private function onCreateHandler() | ||
{ | ||
$loop = $this->getLoop(); | ||
|
||
$loop->addPeriodicTimer(1, function() { | ||
echo 'Runtime::[' . $this->getAlias() . '] is alive and ' . time() . PHP_EOL; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
namespace App\Process\Test; | ||
|
||
class TestContainer extends \App\Container\Test\TestContainer | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
namespace App\Thread\Test; | ||
|
||
class TestContainer extends \App\Container\Test\TestContainer | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "kraken-php/kraken", | ||
"description": "Kraken Framework", | ||
"keywords": [ | ||
"kraken", "kraken-php", "framework" | ||
], | ||
"license": "MIT", | ||
"type": "project", | ||
"require": { | ||
"php": ">=5.5.9", | ||
"kraken-php/channel": "0.3.*", | ||
"kraken-php/config": "0.3.*", | ||
"kraken-php/console": "0.3.*", | ||
"kraken-php/container": "0.3.*", | ||
"kraken-php/core": "0.3.*", | ||
"kraken-php/environment": "0.3.*", | ||
"kraken-php/event": "0.3.*", | ||
"kraken-php/filesystem": "0.3.*", | ||
"kraken-php/ipc": "0.3.*", | ||
"kraken-php/log": "0.3.*", | ||
"kraken-php/loop": "0.3.*", | ||
"kraken-php/network": "0.3.*", | ||
"kraken-php/promise": "0.3.*", | ||
"kraken-php/root": "0.3.*", | ||
"kraken-php/runtime": "0.3.*", | ||
"kraken-php/stream": "0.3.*", | ||
"kraken-php/supervision": "0.3.*", | ||
"kraken-php/throwable": "0.3.*", | ||
"kraken-php/util": "0.3.*" | ||
}, | ||
"require-dev": { | ||
"kraken-php/test": "0.3.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "app" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"App\\Test\\": "test" | ||
} | ||
}, | ||
"config": { | ||
"vendor-dir": "vendor" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "0.4-dev" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$loader = require_once $basePath . '/vendor/autoload.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
global $argv; | ||
global $argc; | ||
|
||
if (!defined('STDIN') || $argc < 3) | ||
{ | ||
echo("Tried to execute program outside of CLI mode or not enough parameters have been passed.\n"); | ||
exit(1); | ||
} | ||
|
||
$controller = null; | ||
$parent = (string) $argv[1]; | ||
$alias = (string) $argv[2]; | ||
$name = (string) $argv[3]; | ||
$args = []; | ||
|
||
for ($i=4; ; $i++) | ||
{ | ||
if (!isset($argv[$i])) | ||
{ | ||
break; | ||
} | ||
|
||
$arg = explode('=', ltrim($argv[$i], '-')); | ||
$args[$arg[0]] = $arg[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* Class Error does not exists in PHP5, so here we create a "mock" for it based on Exception. | ||
* After that procedure we have hierarchy: | ||
* | ||
* /Exception | ||
* /Kraken/Throwable/Exception | ||
* /Error | ||
* /Kraken/Throwable/Error | ||
* | ||
* ... in PHP5, and | ||
* | ||
* /Exception | ||
* /Kraken/Throwable/Exception | ||
* /Error | ||
* /Kraken/Throwable/Error | ||
* | ||
* ... in PHP7 | ||
* | ||
* due to this hierarchy all catch blocks must consist of both catch (Error $ex) and catch (Exception $ex) in this | ||
* particular order!!! [...] | ||
* | ||
* try | ||
* { | ||
* // some code | ||
* } | ||
* catch (Error $ex) | ||
* { | ||
* // will catch /Error in PHP5 | ||
* // will catch /Error in PHP7 | ||
* // will catch /Kraken/Throwable/Error in PHP5 | ||
* // will catch /Kraken/Throwable/Error in PHP7 | ||
* } | ||
* catch (Exception $ex) | ||
* { | ||
* // will catch /Exception in PHP5 | ||
* // will catch /Exception in PHP7 | ||
* // will catch /Kraken/Throwable/Exception in PHP5 | ||
* // will catch /Kraken/Throwable/Exception in PHP7 | ||
* } | ||
* | ||
* [...] and all methods that expects Exception should expect now Error|Exception, ex: | ||
* | ||
* before: | ||
* param Exception $ex | ||
* public function someMethod(Exception $ex) | ||
* | ||
* now: | ||
* param Error|Exception $ex | ||
* public function someMethod($ex) | ||
*/ | ||
if (!class_exists('Error')) | ||
{ | ||
class Error extends Exception | ||
{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* Declare paths & variables | ||
*/ | ||
$dataPath = realpath(__DIR__ . '/..'); | ||
$basePath = realpath($dataPath . '/..'); | ||
|
||
$controller = isset($controller) ? $controller : null; | ||
$loader = isset($loader) ? $loader : null; | ||
|
||
/** | ||
* Include autoloader & dependencies. | ||
*/ | ||
require $dataPath . '/autorun/autorun.php5.polyfill'; | ||
require_once $dataPath . '/autorun/autoload'; | ||
require_once $dataPath . '/autorun/autorun.params'; | ||
|
||
/** | ||
* Create process instance. | ||
*/ | ||
try | ||
{ | ||
$process = (new \Kraken\Root\Runtime\Boot\ProcessBoot($controller)) | ||
->params([ | ||
'prefix' => 'App', | ||
'name' => $name | ||
]) | ||
->constructor([ | ||
$parent, | ||
$alias, | ||
$name, | ||
$args | ||
]) | ||
->boot( | ||
$dataPath | ||
); | ||
|
||
$process | ||
->create(); | ||
} | ||
catch (\Error $ex) | ||
{ | ||
echo \Kraken\Throwable\Error::toString($ex) . PHP_EOL; | ||
} | ||
catch (\Exception $ex) | ||
{ | ||
echo \Kraken\Throwable\Exception::toString($ex) . PHP_EOL; | ||
} |
Oops, something went wrong.