Skip to content

Instantly share code, notes, and snippets.

@videlalvaro
Created June 9, 2015 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save videlalvaro/96cdba98f4f76e32b2b1 to your computer and use it in GitHub Desktop.
Save videlalvaro/96cdba98f4f76e32b2b1 to your computer and use it in GitHub Desktop.
<?php
include(__DIR__ . '/config.php');
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();
$ch->queue_declare('test', false, true, false, false);
class A {
protected $a;
private $z = 0;
public function __construct($a) {
$this->a = $a;
}
protected function b() {
return $this->a * 2;
}
public function c() {
echo $this->b() + $this->z, "\n";
}
}
$obj = new A(1);
echo "before serialize: ", $obj->c();
$body = serialize($obj);
$msg = new AMQPMessage(serialize($obj));
$ch->basic_publish($msg, '', 'test');
echo "body sent: ", "\n", $body, "\n";
function process_message($msg) {
echo "body received: ", "\n", $msg->body, "\n";
$msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
$uns = unserialize($msg->body);
echo "after unserialize: ", $uns->c();
}
$ch->basic_consume('test', '', false, true, false, false, 'process_message');
// Loop as long as the channel has callbacks registered
while (count($ch->callbacks)) {
$ch->wait();
}
$ch->close();
$conn->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment