Project

General

Profile

1
<?php
2

    
3
/*
4
 * This file is part of the Predis package.
5
 *
6
 * (c) Daniele Alessandri <suppakilla@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

    
12
require 'SharedConfigurations.php';
13

    
14
// This is a basic example on how to use the Predis\MonitorContext class.
15
// You can use redis-cli to send commands to the same Redis instance your client is
16
// connected to, and then type "ECHO QUIT_MONITOR" in redis-cli when you want to
17
// exit the monitor loop and terminate this script in a graceful way.
18

    
19
// Create a client and disable r/w timeout on the socket.
20
$client = new Predis\Client($single_server + array('read_write_timeout' => 0));
21

    
22
// Use only one instance of DateTime, we will update the timestamp later.
23
$timestamp = new DateTime();
24

    
25
foreach (($monitor = $client->monitor()) as $event) {
26
    $timestamp->setTimestamp((int) $event->timestamp);
27

    
28
    // If we notice a ECHO command with the message QUIT_MONITOR, we close the
29
    // monitor context and then break the loop.
30
    if ($event->command === 'ECHO' && $event->arguments === '"QUIT_MONITOR"') {
31
        echo "Exiting the monitor loop...\n";
32
        $monitor->closeContext();
33
        break;
34
    }
35

    
36
    echo "* Received {$event->command} on DB {$event->database} at {$timestamp->format(DateTime::W3C)}\n";
37
    if (isset($event->arguments)) {
38
        echo "    Arguments: {$event->arguments}\n";
39
    }
40
}
41

    
42
// Say goodbye :-)
43
$info = $client->info();
44
print_r("Goodbye from Redis v{$info['redis_version']}!\n");
(6-6/17)