-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.php
43 lines (36 loc) · 1.04 KB
/
results.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
<?php
require('pocket.php');
$ip = $argv[2];
$port = $argv[3];
$pocket = new Pocket($ip, $port, 10, 1);
$snapshot = '';
// event for pushing updates to clients
$pocket->bind('update', function () use (&$pocket, &$snapshot) {
// get database
if (($db = file_get_contents(realpath(dirname(__FILE__)) . '/db.json')) === false)
return;
if (trim($db) == '') return;
// check for updates
if ($db != $snapshot) {
// push updates to all
$pocket->sendAll('update', $db);
$snapshot = $db;
system('clear');
print_r(json_decode($db));
}
});
// event for pushing database to clients
$pocket->bind('pull', function () use (&$pocket, &$snapshot) {
// get database
if (($db = file_get_contents(realpath(dirname(__FILE__)) . '/db.json')) === false)
return;
if (trim($db) == '') return;
// push updates to all
$pocket->sendAll('update', $db);
});
// update clients indefinitely
$pocket->onRun(function () use (&$pocket) {
$pocket->call('update');
});
$pocket->open();
?>