1 | 2 | simandl | <?php |
2 | | | |
3 | | | namespace Phem\Libraries\MessageBus; |
4 | | | |
5 | | | use Phem\Environment\ApplicationException; |
6 | | | use Ratchet\WebSocket\Version\RFC6455\Message; |
7 | | | |
8 | | | /** |
9 | | | * @author Jakub PetrĹžĂlka <petrzilka@czweb.net> |
10 | | | */ |
11 | | | class CometPusher extends Pusher |
12 | | | { |
13 | | | |
14 | | | public function push($message) |
15 | | | { |
16 | | | if (!function_exists("posix_kill")) |
17 | | | { |
18 | | | throw new ApplicationException('Posix support is missing'); |
19 | | | } |
20 | | | |
21 | | | $username = $message->getToUsr(); |
22 | | | if ($username == null) |
23 | | | { |
24 | | | foreach (self::getLoggedUsers() as $user) |
25 | | | { |
26 | | | self::setVar('user.queue.' . $user->getSession() |
27 | | | . '.' . $message->getId(), $message); |
28 | | | } |
29 | | | |
30 | | | //$iter = new \APCIterator('user', '/user.pid./'); |
31 | | | $iter = \xcache_list(XC_TYPE_VAR, 0)['cache_list']; |
32 | | | foreach ($iter as $item) |
33 | | | { |
34 | | | if (strpos($item["name"], 'user.pid') === false) |
35 | | | { |
36 | | | continue; |
37 | | | } |
38 | | | posix_kill(self::getVar($item['name']), SIGUSR1); |
39 | | | } |
40 | | | } |
41 | | | else |
42 | | | { |
43 | | | foreach (self::getUserSessions($username) as $session) |
44 | | | { |
45 | | | self::setVar('user.queue.' . $session |
46 | | | . '.' . $message->getId(), $message); |
47 | | | $pid = self::getVar('user.pid.' . $session); |
48 | | | |
49 | | | posix_kill($pid, SIGUSR1); |
50 | | | } |
51 | | | } |
52 | | | } |
53 | | | |
54 | | | } |