-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.php
More file actions
30 lines (22 loc) · 757 Bytes
/
app.php
File metadata and controls
30 lines (22 loc) · 757 Bytes
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
<?php
use Workerman\Worker;
use PHPSocketIO\SocketIO;
date_default_timezone_set('Europe/Samara');
require_once __DIR__ . '/vendor/autoload.php';
$io = new SocketIO(3120);
$io->on('connection', function ($client) use ($io) {
echo "new connection coming\n";
$client->nickname = 'Кто-то #'.rand(1,1000);
$client->on('new_message', function ($msg) use ($io, $client) {
echo "[new_message]: $msg\n";
$client->broadcast->emit('new_message', [
'user' => $client->nickname,
'msg' => $msg,
'date' => date('d.m.Y H:i:s')
]);
});
$client->on('disconnect', function () use ($io, $client) {
echo "user disconnected\n";
});
});
Worker::runAll();