Discussion:
[rabbitmq-users] issue with php-amqplib
g***@me.com
2015-06-11 23:01:52 UTC
Permalink
This is the problem.



***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp# php
amqp_publisher_with_confirms.php

PHP Catchable fatal error: Argument 1 passed to
PhpAmqpLib\Channel\AMQPChannel::set_ack_handler() must be an instance of
PhpAmqpLib\Channel\Callable, instance of Closure given, called in
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php on line 17
and defined in
/var/apache2/2.2/htdocs/amqp/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php
on line 1045

PHP Stack trace:

PHP 1. {main}()
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php:0

PHP 2. PhpAmqpLib\Channel\AMQPChannel->set_ack_handler()
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php:17

***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp# cat
amqp_publisher_with_confirms.php

<?php


use PhpAmqpLib\Connection\AMQPConnection;

use PhpAmqpLib\Message\AMQPMessage;


include(__DIR__ . '/config.php');


$exchange = 'someExchange';


$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);

$ch = $conn->channel();


$ch->set_ack_handler(

function (AMQPMessage $message) {

echo "Message acked with content " . $message->body . PHP_EOL;

}

);


$ch->set_nack_handler(

function (AMQPMessage $message) {

echo "Message nacked with content " . $message->body . PHP_EOL;

}

);


/*

* bring the channel into publish confirm mode.

* if you would call $ch->tx_select() befor or after you brought the
channel into this mode

* the next call to $ch->wait() would result in an exception as the publish
confirm mode and transactions

* are mutually exclusive

*/

$ch->confirm_select();


/*

name: $exchange

type: fanout

passive: false // don't check is an exchange with the same name exists

durable: false // the exchange won't survive server restarts

auto_delete: true //the exchange will be deleted once the channel is
closed.

*/


$ch->exchange_declare($exchange, 'fanout', false, false, true);


$i = 1;

$msg = new AMQPMessage($i, array('content_type' => 'text/plain'));

$ch->basic_publish($msg, $exchange);


/*

* watching the amqp debug output you can see that the server will ack the
message with delivery tag 1 and the

* multiple flag probably set to false

*/


$ch->wait_for_pending_acks();


while ($i <= 11) {

$msg = new AMQPMessage($i++, array('content_type' => 'text/plain'));

$ch->basic_publish($msg, $exchange);

}


/*

* you do not have to wait for pending acks after each message sent. in
fact it will be much more efficient

* to wait for as many messages to be acked as possible.

*/

$ch->wait_for_pending_acks();


$ch->close();

$conn->close();

***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp#
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Klishin
2015-06-11 23:06:50 UTC
Permalink
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner  a bit? We are not great at mind reading
on this list.

We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
g***@me.com
2015-06-11 23:12:40 UTC
Permalink
Yes, sorry. Tying to run the publisher with confirms got into problems
registering the ack and nack callback functions.
Not to use my own code, i tried running the provided example in
php-amqplib. The example fails indicating that for set_ack_handler(), and
instance of Callable must be used, instead of Closure given.
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great at
mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
g***@me.com
2015-06-11 23:14:38 UTC
Permalink
<script
src="https://gist.github.com/anonymous/7c59feef4f5a0d5d3850.js"></script>
Post by g***@me.com
Yes, sorry. Tying to run the publisher with confirms got into problems
registering the ack and nack callback functions.
Not to use my own code, i tried running the provided example in
php-amqplib. The example fails indicating that for set_ack_handler(), and
instance of Callable must be used, instead of Closure given.
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great at
mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Klishin
2015-06-11 23:15:32 UTC
Permalink
Post by g***@me.com
The example fails indicating that for set_ack_handler(),
and instance of Callable must be used, instead of Closure given.
What version of PHP is used?
--
MK

Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
g***@me.com
2015-06-11 23:19:07 UTC
Permalink
Version of PHP is 5.3.8

***@sis-mqueue11:~$ php -version

PHP 5.3.28 (cli) (built: Jun 17 2014 13:24:21)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans

with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great at
mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alvaro Videla
2015-06-12 05:41:27 UTC
Permalink
The code here, works perfectly with PHP 5.4.6:
https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_publisher_with_confirms.php

Also as MK said, please try to share Github Gists, not this code
copy&pasted with format; it's quite hard for us to read that.

If your function is not treated as an Anon Function in PHP, then that has
to do with your PHP version probably, not with the library.

The functions on php-amqplib setting callback handlers don't type hint,
they just check for is_callable:
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1441

This class error you get is because PHP doesn't scope the "Callable"
interface properly for some reason. That's a PHP interface, it has nothing
to do with this PHP library.

Can you use Anon Functions that way in your code with say, array_map?
Post by g***@me.com
Version of PHP is 5.3.8
PHP 5.3.28 (cli) (built: Jun 17 2014 13:24:21)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great at
mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups
"rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
g***@me.com
2015-06-12 11:34:33 UTC
Permalink
Sorry for the copy and paste. This is standard out of the box solaris PHP
V5.3. Not a PHP expert, but what is the difference between Callable and
callable?
Post by Alvaro Videla
https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_publisher_with_confirms.php
Also as MK said, please try to share Github Gists, not this code
copy&pasted with format; it's quite hard for us to read that.
If your function is not treated as an Anon Function in PHP, then that has
to do with your PHP version probably, not with the library.
The functions on php-amqplib setting callback handlers don't type hint,
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1441
This class error you get is because PHP doesn't scope the "Callable"
interface properly for some reason. That's a PHP interface, it has nothing
to do with this PHP library.
Can you use Anon Functions that way in your code with say, array_map?
Post by g***@me.com
Version of PHP is 5.3.8
PHP 5.3.28 (cli) (built: Jun 17 2014 13:24:21)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great at
mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups
"rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
g***@me.com
2015-06-12 11:40:25 UTC
Permalink
I just checked and both is_callable and array map work perfectly fine.I
tried all the examples for the
manual http://php.net/manual/en/function.is-callable.php
and http://php.net/manual/en/function.array-map.php and they work.
The prototype in AQMPChannle.php referers to a Callable type. Where is that
defined? I think the problem might be that V5.3, which is mentioned as
required by the package php-amqplib, does not implement that Callable type?
Post by Alvaro Videla
https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_publisher_with_confirms.php
Also as MK said, please try to share Github Gists, not this code
copy&pasted with format; it's quite hard for us to read that.
If your function is not treated as an Anon Function in PHP, then that has
to do with your PHP version probably, not with the library.
The functions on php-amqplib setting callback handlers don't type hint,
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1441
This class error you get is because PHP doesn't scope the "Callable"
interface properly for some reason. That's a PHP interface, it has nothing
to do with this PHP library.
Can you use Anon Functions that way in your code with say, array_map?
Post by g***@me.com
Version of PHP is 5.3.8
PHP 5.3.28 (cli) (built: Jun 17 2014 13:24:21)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great at
mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google Groups
"rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alvaro Videla
2015-06-12 12:05:34 UTC
Permalink
The Callable interface came and went in the 5.3.x released I think. Perhaps
upgrading PHP solves that.
Post by g***@me.com
I just checked and both is_callable and array map work perfectly fine.I
tried all the examples for the manual
http://php.net/manual/en/function.is-callable.php and
http://php.net/manual/en/function.array-map.php and they work.
The prototype in AQMPChannle.php referers to a Callable type. Where is
that defined? I think the problem might be that V5.3, which is mentioned as
required by the package php-amqplib, does not implement that Callable type?
Post by Alvaro Videla
https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_publisher_with_confirms.php
Also as MK said, please try to share Github Gists, not this code
copy&pasted with format; it's quite hard for us to read that.
If your function is not treated as an Anon Function in PHP, then that has
to do with your PHP version probably, not with the library.
The functions on php-amqplib setting callback handlers don't type hint,
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1441
This class error you get is because PHP doesn't scope the "Callable"
interface properly for some reason. That's a PHP interface, it has nothing
to do with this PHP library.
Can you use Anon Functions that way in your code with say, array_map?
Version of PHP is 5.3.8
Post by Alvaro Videla
Post by g***@me.com
PHP 5.3.28 (cli) (built: Jun 17 2014 13:24:21)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great
at mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google
Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
Post by g***@me.com
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
g***@me.com
2015-06-12 12:08:32 UTC
Permalink
Unfortunately solaris supports (by Oracle) is limited to 5.3 of PHP. While
we could download and compile, it would not be supported.
Is there a workaround?
Post by Alvaro Videla
The Callable interface came and went in the 5.3.x released I think.
Perhaps upgrading PHP solves that.
Post by g***@me.com
I just checked and both is_callable and array map work perfectly fine.I
tried all the examples for the manual
http://php.net/manual/en/function.is-callable.php and
http://php.net/manual/en/function.array-map.php and they work.
The prototype in AQMPChannle.php referers to a Callable type. Where is
that defined? I think the problem might be that V5.3, which is mentioned as
required by the package php-amqplib, does not implement that Callable type?
Post by Alvaro Videla
https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_publisher_with_confirms.php
Also as MK said, please try to share Github Gists, not this code
copy&pasted with format; it's quite hard for us to read that.
If your function is not treated as an Anon Function in PHP, then that
has to do with your PHP version probably, not with the library.
The functions on php-amqplib setting callback handlers don't type hint,
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1441
This class error you get is because PHP doesn't scope the "Callable"
interface properly for some reason. That's a PHP interface, it has nothing
to do with this PHP library.
Can you use Anon Functions that way in your code with say, array_map?
Version of PHP is 5.3.8
Post by Alvaro Videla
Post by g***@me.com
PHP 5.3.28 (cli) (built: Jun 17 2014 13:24:21)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great
at mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google
Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send
Post by g***@me.com
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alvaro Videla
2015-06-12 12:09:31 UTC
Permalink
Try defining your callable in any of the other callable formats. The PHP
docs on callable explain that.
Post by g***@me.com
Unfortunately solaris supports (by Oracle) is limited to 5.3 of PHP. While
we could download and compile, it would not be supported.
Is there a workaround?
Post by Alvaro Videla
The Callable interface came and went in the 5.3.x released I think.
Perhaps upgrading PHP solves that.
Post by g***@me.com
I just checked and both is_callable and array map work perfectly fine.I
tried all the examples for the manual
http://php.net/manual/en/function.is-callable.php and
http://php.net/manual/en/function.array-map.php and they work.
The prototype in AQMPChannle.php referers to a Callable type. Where is
that defined? I think the problem might be that V5.3, which is mentioned as
required by the package php-amqplib, does not implement that Callable type?
Post by Alvaro Videla
https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_publisher_with_confirms.php
Also as MK said, please try to share Github Gists, not this code
copy&pasted with format; it's quite hard for us to read that.
If your function is not treated as an Anon Function in PHP, then that
has to do with your PHP version probably, not with the library.
The functions on php-amqplib setting callback handlers don't type hint,
https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php#L1441
This class error you get is because PHP doesn't scope the "Callable"
interface properly for some reason. That's a PHP interface, it has nothing
to do with this PHP library.
Can you use Anon Functions that way in your code with say, array_map?
Version of PHP is 5.3.8
Post by Alvaro Videla
Post by g***@me.com
PHP 5.3.28 (cli) (built: Jun 17 2014 13:24:21)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Post by g***@me.com
This is the problem.
Would you mind elaborating on this one liner a bit? We are not great
at mind reading
on this list.
We'd also appreciate if you use gist.github.com for code snippets
instead of posting green-on-black code walls to the list.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
--
You received this message because you are subscribed to the Google
Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send
Post by g***@me.com
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...