Last active
November 19, 2015 05:51
-
-
Save Rijen/52b6013920a00e091036 to your computer and use it in GitHub Desktop.
Автозагрузка.
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
[Thu, 19 Nov 2015 07:12:06.980016 +0300] M#43582 \PHPDaemon\Core\Pool:Servers\WebSocket up. | |
[Thu, 19 Nov 2015 07:12:06.994425 +0300] M#43582 \PHPDaemon\Core\Pool:\PHPDaemon\Servers\WebSocket\Pool up. | |
[Thu, 19 Nov 2015 07:12:07.015732 +0300] W#43584 \MyWebSocket up. | |
[Thu, 19 Nov 2015 07:12:08.216939 +0300] Spawning 1 worker(s) | |
[Thu, 19 Nov 2015 07:12:08.533961 +0300] W#43586 \MyWebSocket up. | |
[Thu, 19 Nov 2015 07:12:12.417157 +0300] W#43584 crashed by error 'Class 'Test' not found' at /var/www/rijen/1a/server/MyWebSocket.php:78 | |
[Thu, 19 Nov 2015 07:12:12.437178 +0300] Spawning 1 worker(s) | |
[Thu, 19 Nov 2015 07:12:12.753582 +0300] W#43589 \MyWebSocket up. |
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
{ | |
"name": "rijen", | |
"autoload": { | |
"psr-4": { | |
"App\\": "src/" | |
} | |
} | |
} |
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
<?php | |
require_once './vendor/autoload.php'; | |
use \App; | |
class MyWebSocket extends \PHPDaemon\Core\AppInstance | |
{ | |
public function onReady() | |
{ | |
$appInstance = $this; | |
// Метод timerTask() будет вызываться каждые 5 секунд | |
// $this->timerTask($appInstance); | |
// Наше приложение будет доступно по адресу ws://site.com:8047/myws | |
\PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('myws', function ($client) use ($appInstance) | |
{ | |
$session = new MyWebSocketRoute($client, $appInstance); // Создаем сессию | |
$session->id = uniqid(); // Назначаем ей уникальный ID | |
$this->sessions[$session->id] = $session; //Сохраняем в массив | |
return $session; | |
}); | |
} | |
//some code | |
} | |
class MyWebSocketRoute extends \PHPDaemon\WebSocket\Route | |
{ | |
//some code | |
public function onFrame($data, $type) | |
{ | |
$this->client->sendFrame(Test::test(), 'STRING'); | |
} | |
} |
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
<?php | |
namespace App; | |
Class Test | |
{ | |
static function test() | |
{ | |
return 123; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need
use \App\Test;
notuse \App;