-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.php
58 lines (49 loc) · 1.69 KB
/
server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* User: boshurik
* Date: 06.05.16
* Time: 13:10
*/
require_once __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$application = new BoShurik\WebSocket\Application();
/**
* RabbitMQ
*/
$client = new \Bunny\Async\Client($loop);
$client->connect()->then(function(\Bunny\Async\Client $client){
return $client->channel();
})->then(function(\Bunny\Channel $channel){
return \React\Promise\all(array(
$channel,
$channel->queueDeclare("queue"),
$channel->exchangeDeclare("exchange"),
$channel->queueBind("queue", "exchange"),
));
})->then(function($data) use ($application){
/** @var \Bunny\Channel $channel */
$channel = $data[0];
return $channel->consume(function (\Bunny\Message $msg, \Bunny\Channel $ch, \Bunny\Async\Client $c) use ($application) {
$application->onMessage($msg->content);
}, "queue", "", false, true);
});
/**
* Socket
*/
//$socket = new React\Socket\Server($loop);
//$socket->on('connection', function ($conn) use ($application) {
// $conn->on('data', array($application, 'onMessage'));
//});
//$socket->listen(1337);
/**
* ZeroMQ
*/
//// Listen for the web server to make a ZeroMQ push after an ajax request
//$context = new React\ZMQ\Context($loop);
//$pull = $context->getSocket(ZMQ::SOCKET_PULL);
//$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
//$pull->on('messa∂ge', array($application, 'onMessage'));
$app = @new \Ratchet\App('127.0.0.1', 8888, '0.0.0.0', $loop); // Binding to 0.0.0.0 means remotes can connect
$app->route('/ws', $application, array('*'));
echo "\nServer has been running\n\n";
$app->run();