Last active
January 6, 2018 10:39
-
-
Save vtvz/cdc1e321ec2e5b7cc3803cdf1c68f759 to your computer and use it in GitHub Desktop.
stream_select with rabbitmq example
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 | |
/* | |
Some code here | |
More info here (Russian): https://www.facebook.com/vtvz.ru/posts/1612858868772444 | |
*/ | |
$stdin = fopen('php://stdin', 'r'); | |
$rabbitmq = $connection->getSocket(); | |
while (count($channel->callbacks)) { | |
$read = [$rabbitmq, $stdin]; | |
$write = null; | |
$except = null; | |
if (false === ($changeStreamsCount = stream_select($read, $write, $except, 60))) { | |
// Error handling | |
} elseif ($changeStreamsCount > 0) { | |
foreach ($read as $fd) { | |
if ($fd === $stdin) { | |
$line = fgets($stdin); | |
//Do something with input data | |
} elseif ($fd === $rabbitmq) { | |
$channel->wait(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment