0

Few weeks ago I set up a Message system with Symfony Messenger and it worked great.

Today I wanted to create new object through message, so I went to my server and type the command to consume message

First I had this result

$ bin/console messenger:consume-messages amqp_notifications
/usr/bin/env: ‘php\r’: No such file or directory

It never happened before with my files, and I never changed the line ending or encoding of my file sin PHPstorm.

I tried to use $ php bin/console messenger:consume-messages amqp_notifications but then I had this error.

  Attempted to load class "AMQPConnection" from the global namespace.
  Did you forget a "use" statement?

Pretty weird, because I have have the php-amqp ext installed as you can see on the screenshot of my phpinfo enter image description here

I didn't change anything in my Message class or Handler.

Also, I tried to call new AMQPConnection() on a random action, just to try, and I didn't get the error.

I'm completely lost with this error this time, as everything is installed.

I use PHP 7.3.1 and symfony Messenger 4.2.2

Etshy
  • 870
  • 7
  • 25
  • Are you sure your CLI and httpd are using the same php version? Try calling `php -v` and `php -i` from the command line and ensure your CLI has the php-amqp extension loaded aswell. – ccKep Jan 30 '19 at 23:04
  • I don't see `amqp` with `php -i`... I updated from 7.3.0 to 7.3.1 and both cli and httpd were upgraded, so I thought it was the same version. I added the `extension=amqp` line in the cli php.ini and it worked. weird, I didn't had to do that when I installed php 7.1 or 7.2. and weaird too that mongo ext is loaded when there is no `extension=mongo` in the cli ini. Thanks a lot for that problem. About the `/usr/bin/env: ‘php\r’: No such file or directory` do you have an idea why it came suddenly ? – Etshy Jan 30 '19 at 23:21

1 Answers1

1

It seems your second issue was already solved by ccKep on his comment.

The first one is that the specific shebang line #!/usr/bin/env php executes the first php found in the $PATH. So if you already have uninstalled it, which seems the case, or it has a symbolic link to another php version, you can get a wrong result.

Tries to check what is inside the $PATH and replace the PHP path for the correct one. You might get the place running which php.

  • Hmm, indeed in my PATH I have the folowing (for my user) : `/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games`. I looked in these folders, in `/usr.bin`, I have multiple php (`php`, `php7.2` and `php7.3`) When I installed php7.3, I did a purge for php7.2, but seems there is still traces. How I can solve that ? – Etshy Jan 31 '19 at 07:16
  • I would check which PHP is been executed by your webserver, and then there are two alternatives: 1. You can change shebang on the bin/console file to the absolute path of the PHP 2. Create a symlink to the PHP version you want `sudo ln -s {absolute-path-of-the-php-you-want} /usr/local/bin/php` This will replace the php executed to the one you want. – Jorge Vahldick Jan 31 '19 at 09:09
  • OKay I'll take a look at that. If I remember both `php -v` and `php7.3 -v` returned the same thing though, so I think it's already the same. I'll check what there is in my `bin/console` file and recreate a symlink from `/usr/bin/php7.3` to `/usr/bin/php` to make sure. Will keep you in touch if I have more problem. Thanks a lot ! – Etshy Jan 31 '19 at 11:03
  • Tired to change the shebang to `#!/usr/bin/php` but I got this error `-bash: bin/console: /usr/bin/php^M: bad interpreter: No such file or directory` the `/usr/bin/php` is valid, I cans do `/usr/bin/php -v` without problem. – Etshy Jan 31 '19 at 12:11
  • Ok, got the issue. It seems your file is using DOS line endings (CRLF), and possibly I believe you are trying to execute the script from some unix terminal. Try to change the end of the line to LF. I don't know if you use some IDE, but PHP Storm or Notepad++ can solve it easily by an option in their bottom bar. – Jorge Vahldick Jan 31 '19 at 13:09
  • Yeah I tried to change all my files to LF few hours ago and now I came back It seems to be working. really weird I didn't had this problem before and weird that git didn't detect the CRLF and warn me. – Etshy Jan 31 '19 at 17:26