1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- require 'SharedConfigurations.php';
- $client = new Predis\Client($single_server + array('read_write_timeout' => 0));
- $pubsub = $client->pubSub();
- $pubsub->subscribe('control_channel', 'notifications');
- foreach ($pubsub as $message) {
- switch ($message->kind) {
- case 'subscribe':
- echo "Subscribed to {$message->channel}\n";
- break;
- case 'message':
- if ($message->channel == 'control_channel') {
- if ($message->payload == 'quit_loop') {
- echo "Aborting pubsub loop...\n";
- $pubsub->unsubscribe();
- } else {
- echo "Received an unrecognized command: {$message->payload}.\n";
- }
- } else {
- echo "Received the following message from {$message->channel}:\n",
- " {$message->payload}\n\n";
- }
- break;
- }
- }
- unset($pubsub);
- $info = $client->info();
- print_r("Goodbye from Redis v{$info['redis_version']}!\n");
|