A
A
andrei_pro2019-04-07 20:05:01
PHP
andrei_pro, 2019-04-07 20:05:01

PHP persistent connection?

Hello.
Is it possible to make a persistent connection to the queuing service? At high load there are problems with the connection.
Stack: nginx, php-fpm, rabbitmq

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2019-04-07
@politon

Sockets
https://www.php.net/manual/en/book.sockets.php

P
Pavel Belyaev, 2019-04-09
@PavelBelyaev

How do you work with queues in general? Do you think with a permanent connection there will be no problems with falling off?
1. Use a sish client for RabbitMQ, not a PHP library.
2. Use the subscription on the queue, and do not hammer in the cycle for checking for updates, there you simply subscribe to updates and pass the handler function to it, which will be executed at lightning speed when messages are received. An example can be found here
3. You can check the connection like this (if you have the amqp library)

if ($conn->isConnected()) {
    echo "Connected to the broker \o/";
}
else {
    echo "Cannot connect to the broker";
}

well, reconnect ...
4. If there are several servers, then it probably makes sense to install RabbitMQ locally everywhere and configure clustering

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question