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

onurzdgn's avatar

Post data with API and zmq

I am sending data with zmq. Now I need api then zmq. Firstly my data will go api then my zmq block will send this data from api. How can I do? My zmq block: `` $queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ);

        $queue->connect("tcp://127.0.0.1:6116");

        $queue->send($flag, ZMQ::MODE_SNDMORE);

        $queue->send($startScan, ZMQ::MODE_NOBLOCK);

        $abc = $queue->recvMulti();
0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

You can use the Guzzle HTTP client to make an API request and then send the data from the response to your ZMQ block.

First, install Guzzle with Composer:

composer require guzzlehttp/guzzle

Then, you can use the following code to make an API request and send the response data to your ZMQ block:

use GuzzleHttp\Client;

$client = new Client();
$response = $client->request('GET', 'https://example.com/api/endpoint');
$data = $response->getBody()->getContents();

$queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ);
$queue->connect("tcp://127.0.0.1:6116");

$queue->send($flag, ZMQ::MODE_SNDMORE);
$queue->send($data, ZMQ::MODE_NOBLOCK);

$abc = $queue->recvMulti();
1 like

Please or to participate in this conversation.