/
ZMQProxy.php
38 lines (28 loc) · 865 Bytes
/
ZMQProxy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* Created by PhpStorm.
* User: henrygrech-cini
* Date: 30/10/2014
* Time: 22:48
*/
// A very simple HTTP to ZMQ Proxy
// This could be setup as an asynchronous proxy
// but currently we wait for the response.
// The socket can also be invoked externally
// port 5454 has been opened on the AWS EC2 instance
// code to show the code
echo 'Code shown here to illustrate'.PHP_EOL;
echo show_source(__FILE__);
// the actual code
// create the ZMQ Context and Socket
$ctx=new ZMQContext();
$req=new ZMQSocket($ctx, ZMQ::SOCKET_REQ);
// connect to the ZMQ
$req->connect('tcp://localhost:5454');
// prepare the message to send to ZMQ
$message=isset($_GET['msg'])?$_GET['msg']:'Default Hello';
// send the prepared message
$req->send($message);
// output the response
echo PHP_EOL.'[ '.$req->recv().' ]'.PHP_EOL;
// Actual Response SHOW BELOW //