-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathmonitor.php
More file actions
44 lines (35 loc) · 1.07 KB
/
monitor.php
File metadata and controls
44 lines (35 loc) · 1.07 KB
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
<?php
/**
* This file is part of RedisClient.
* git: https://github.com/cheprasov/php-redis-client
*
* (C) Alexander Cheprasov <acheprasov84@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Monitor
*/
namespace Examples;
require (dirname(__DIR__).'/vendor/autoload.php');
// or require (dirname(__DIR__).'/src/autoloader.php');
use RedisClient\RedisClient;
// Example 1. monitor with timeout
$Redis = new RedisClient([
'timeout' => 10 // for waiting answer for 10 seconds
]);
$Redis->monitor(function($message) {
// This function will be called on message and on timeout
if (!isset($message)) {
echo 'No any message for 10 second... exit'. PHP_EOL;
// return <false> for stop monitoring and exit
return false;
}
echo $message, PHP_EOL;
// return <true> for to wait next message
return true;
});
// NOTE! You can not use $Redis after monitor,
// because connection with redis will be closed,
// it is correct way to stop monitor.