Skip to content

Instantly share code, notes, and snippets.

@vtvz
Last active January 6, 2018 10:39
Show Gist options
  • Save vtvz/cdc1e321ec2e5b7cc3803cdf1c68f759 to your computer and use it in GitHub Desktop.
Save vtvz/cdc1e321ec2e5b7cc3803cdf1c68f759 to your computer and use it in GitHub Desktop.
stream_select with rabbitmq example
<?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