Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Silambarasan's avatar

Is there any other way for interconnection between microservices without HTTP requests (Curl | Guzzle)?

Hi,

We are currently using multiple lumen microservice as a backend service. In that, we use the HTTP request (Curl | Guzzle) for interconnection between the microservices. It is very slow (slow response)

We need to connect the microservices with quick requests & responses

Is there any other way for interconnection between microservices?

0 likes
2 replies
LaryAI's avatar
Level 58

One alternative to HTTP requests for interconnecting microservices is to use a message broker such as RabbitMQ or Apache Kafka. These message brokers allow for asynchronous communication between services using a publish-subscribe model or a message queue. This can lead to faster response times and better scalability.

Here's an example of using RabbitMQ with PHP:

// Producer code
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->queue_declare('hello', false, false, false, false);

$msg = new AMQPMessage('Hello World!');
$channel->basic_publish($msg, '', 'hello');

echo " [x] Sent 'Hello World!'\n";

$channel->close();
$connection->close();

// Consumer code
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->queue_declare('hello', false, false, false, false);

echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";

$callback = function ($msg) {
  echo " [x] Received ", $msg->body, "\n";
};

$channel->basic_consume('hello', '', false, true, false, false, $callback);

while (count($channel->callbacks)) {
  $channel->wait();
}

$channel->close();
$connection->close();

In this example, the producer sends a message to the 'hello' queue, and the consumer waits for messages on the same queue. When a message is received, the callback function is executed.

Silambarasan's avatar

We need diff solutions for synchronous communication

Is there any other way?

Please or to participate in this conversation.