Created
June 6, 2018 14:28
-
-
Save insytes/656b33c19a33a9e49254e4de081c3d72 to your computer and use it in GitHub Desktop.
ReactPHP Redis Pub/Sub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
ini_set("display_errors", 1); | |
ini_set("default_socket_timeout", 10); | |
require __DIR__ . "/../../vendor/autoload.php"; | |
$loop = React\EventLoop\Factory::create(); | |
$factory = new Factory($loop); | |
$channel = isset($argv[1]) ? $argv[1] : "default"; | |
$factory->createClient("redis://:[email protected]:6379")->then(function (Clue\React\Redis\Client $client) use ($channel) { | |
$client->subscribe($channel)->then(function () use (&$channel) { | |
echo "Now subscribed to $channel " . PHP_EOL; | |
}); | |
$client->on("message", function ($channel, $message) { | |
echo 'Message on ' . $channel . ': ' . $message . PHP_EOL; | |
}); | |
}, function (Exception $e) { | |
print $e->getMessage() . "\n"; | |
}); | |
$loop->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment