Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined constant AMQP_NOPARAM in AmqpStamp #54682

Closed
musahcoding opened this issue Apr 20, 2024 · 18 comments
Closed

Undefined constant AMQP_NOPARAM in AmqpStamp #54682

musahcoding opened this issue Apr 20, 2024 · 18 comments

Comments

@musahcoding
Copy link

Symfony version(s) affected

6.3.12

Description

I just tried to use this package symfony/amqp-messenger@6.3.12 last night and today noticed that I am receiving this exception:

"message": "Uncaught PHP Exception Error: \"Undefined constant \"AMQP_NOPARAM\"\" at /var/www/html/modeer-web-app/vendor/symfony/amqp-messenger/Transport/AmqpStamp.php line 27",
  "context": {
    "exception": {
      "class": "Error",
      "message": "Undefined constant \"AMQP_NOPARAM\"",
      "code": 0,
      "file": "/var/www/html/modeer-web-app/vendor/symfony/amqp-messenger/Transport/AmqpStamp.php:27"
    }
  },
  "level": 500,
  "level_name": "CRITICAL",
  "channel": "request",
  "datetime": "2024-04-20T17:02:33.166481+04:30",
  "extra": {}
}

And when I search for the definition of the constant AMQP_NOPARAM in vendor/symfony/amqp-messenger, it seems it is not defined. To do a workaround I created this file at scripts/amqp-constants.php:

<?php

if (!defined('AMQP_NOPARAM')) {
    define('AMQP_NOPARAM', 0);
}

and added the following to composer.json:

    "autoload": {
        "files": ["scripts/amqp-constants.php"],

But it does not really look the right thing for me, I must have been missing something or is it a bug?

How to reproduce

I mentioned all the code above.

Possible Solution

I added my workaround above, maybe it could also be moved to the repo itself?

Additional Context

No response

@derrabus
Copy link
Member

derrabus commented Apr 20, 2024

6.3.12

Note that this Symfony version is not maintained anymore. Even if you've identified a bug, you won't get any bugfixes unless you upgrade to a newer version.

I must have been missing something or is it a bug?

The AMQP extension might be the something that you're missing.

@musahcoding
Copy link
Author

musahcoding commented Apr 21, 2024 via email

@derrabus
Copy link
Member

But the constant that you're missing should be defined by the AMQP extension. Maybe you're using an old version of it?

@musahcoding
Copy link
Author

musahcoding commented Apr 21, 2024 via email

@musahcoding
Copy link
Author

@derrabus I am sorry for my above and incorrect reply. I do not have the pecl extension but on Ubuntu 22.04 I have librabbitmq-dev and php-amqp which I insatlled via apt. From the sound of it, these packages do not have that constant 🤔

@discordier
Copy link

@musahcoding having them installed is not enough.
You need to also enable the extension via php.ini (usually something like php-enmod or something along these lines in Ubuntu).

You can check via phpinfo() if the amqp extension is loaded.

@musahcoding
Copy link
Author

musahcoding commented Apr 23, 2024

Thanks for the continued support, I think it is loaded, as I mentioned with that hack publish and consumption work, but also the following commands can confirm it too that the extension is loaded:

modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ php -i | grep rabbitmq
librabbitmq version => 0.10.0
modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ php -i | grep amqp
/etc/php/8.2/cli/conf.d/20-amqp.ini,
amqp
amqp.auto_ack => 0 => 0
amqp.cacert => no value => no value
amqp.cert => no value => no value
amqp.channel_max => 256 => 256
amqp.connect_timeout => 0 => 0
amqp.deserialization_depth => 128 => 128
amqp.frame_max => 131072 => 131072
amqp.global_prefetch_count => 0 => 0
amqp.global_prefetch_size => 0 => 0
amqp.heartbeat => 0 => 0
amqp.host => localhost => localhost
amqp.key => no value => no value
amqp.login => guest => guest
amqp.password => guest => guest
amqp.port => 5672 => 5672
amqp.prefetch_count => 3 => 3
amqp.prefetch_size => 0 => 0
amqp.read_timeout => 0 => 0
amqp.rpc_timeout => 0 => 0
amqp.sasl_method => AMQP_SASL_METHOD_PLAIN => AMQP_SASL_METHOD_PLAIN
amqp.serialization_depth => 128 => 128
amqp.timeout => no value => no value
amqp.verify => 1 => 1
amqp.vhost => / => /
amqp.write_timeout => 0 => 0

Somehow it seems that the apt implementation is different that pecl one. Even if that is the case, I would be happy to follow the pecl installation, but maybe you/we can emphasize in the symfony doc to use the pecl installation or else developers would run into this issue? 🤔

@xabbuh
Copy link
Member

xabbuh commented Apr 24, 2024

Can you also share the output of the following commands?

php -r "var_dump(AMQP_NOPARAM);"
php -r "echo phpversion('amqp');"

@musahcoding
Copy link
Author

Hey!
Here they are:

modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ php -r "var_dump(AMQP_NOPARAM);"
int(0)
modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ php -r "echo phpversion('amqp');"
2.1.2

@derrabus
Copy link
Member

Ubuntu ships the old v1 of the extension. I suspect that v1 does not have the constant (which is just an alias for zero anyway). So the fix might be that we're using 0 instead of the constant in Symfony.

@xabbuh
Copy link
Member

xabbuh commented Apr 24, 2024

So this proves that the constant is defined. Could it be that you run PHP in different contexts (CLI and web for example) and that the other context (the request channel in the log excerpt leads me to this assumption) doesn't have the extension enabled?

@derrabus
Copy link
Member

on Ubuntu 22.04 I have librabbitmq-dev and php-amqp which I insatlled via apt.

modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ php -r "var_dump(AMQP_NOPARAM);"
int(0)
modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ php -r "echo phpversion('amqp');"
2.1.2

This does not add up: Ubunto ships v1: https://packages.ubuntu.com/jammy/php-amqp

@musahcoding
Copy link
Author

@xabbuh I have already checked both web and CLI they use the same extensions.

@derrabus I am using using LAMP image of digital oceans where they have references to more recent versions of PHP 8.3, I see ondrej is also in the list of my sources which has the updates of PHP.

root@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:/home/modeer_devops# ls /etc/apt/sources.list.d/ -l
total 32
-rw-r--r-- 1 root root  130 Oct 18  2023 digitalocean-agent.list
-rw-r--r-- 1 root root  129 Oct 18  2023 droplet-agent.list
-rw-r--r-- 1 root root   58 Apr 20 00:48 focal-security.list
-rw-r--r-- 1 root root  100 Oct 18  2023 nodesource.list
-rw-r--r-- 1 root root  140 Sep  7  2023 ondrej-ubuntu-php-jammy.list
-rw-r--r-- 1 root root 1285 Apr 20 01:02 rabbitmq.list
-rw-r--r-- 1 root root  417 Apr 20 00:49 rabbitmq_rabbitmq-server.list
-rw-r--r-- 1 root root  428 Oct 18  2023 symfony-stable.list

@xabbuh
Copy link
Member

xabbuh commented Apr 29, 2024

<?php

var_dump(AMQP_NOPARAM);
var_dump(phpversion('amqp'));

What is the output of this script when you access it over your web server?

@musahcoding
Copy link
Author

Hey @xabbuh 👋 here it is:

modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ php test.php 
int(0)
string(5) "2.1.2"
modeer_devops@lamp-ubuntu-s-2vcpu-2gb-nyc3-01:~$ cat test.php 
<?php

var_dump(AMQP_NOPARAM);
var_dump(phpversion('amqp'));

@discordier
Copy link

I think he meant you should access it via web SAPI (via browser, curl, ...) instead of CLI SAPI.

@xabbuh
Copy link
Member

xabbuh commented Apr 29, 2024

@discordier is right

@derrabus
Copy link
Member

I think, I'm moving this to support now to reduce the noise on the bug tracker.

@symfony symfony locked and limited conversation to collaborators Apr 29, 2024
@derrabus derrabus converted this issue into discussion #54761 Apr 29, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

5 participants