DS Log
In my blog, I delve into the world of programming web technologies, Linux, Unix-like, and graphic design using free tools on Linux.
KINGCODE
KingCode Editor (ex Texty Editor) is my project developed using Java Swing. Project is still in development and in beta version. I plan to add additional features focused for PYTHON, PHP, JAVA, C, JS and BASH.
Read more ↗
VUE on Linux
In this guide, I'll walk you through the step-by-step process of setting up Vue.js on your Linux system, empowering you to create dynamic and interactive web applications. Let's harness the power of Vue.js together on the Linux platform!
Read more ↗
Symfony PHP
Dive into the world of Symfony PHP with this comprehensive introduction. In this guide, you'll learn the essential steps to create and manage posts and users, empowering you to build dynamic web applications with ease.
Read more ↗
Trying Linux from Windows
How to set up a PHP development server on Ubuntu 22.04
Text editors
List of text editors for developers.
Read more ↗
Fonts
Important fonts everyone needs to know.
Read more ↗
Try Linux from Windows
Here are some quick videos I made showing how to try out Linux Mint on Windows.
Read more ↗
Saturday, August 17, 2024
PHP ZeroMQ

What is ZeroMQ?
ZeroMQ (also known as ØMQ) is a high-performance asynchronous messaging library that provides a message queue for inter-process communication (IPC). It is designed to be lightweight, fast, and flexible, making it suitable for a wide range of applications, from simple messaging systems to complex distributed architectures.
Key Features
- Socket Abstraction: Various socket types for different messaging patterns (e.g., PUB/SUB, REQ/REP).
- Asynchronous I/O: Handle multiple connections without blocking.
- Scalability: Designed to scale from a single machine to distributed systems.
- Transport Protocols: Supports TCP, IPC, and multicast communication.
- No Dedicated Message Broker: Reduces complexity and overhead.
- Lightweight: Suitable for performance-critical applications.
Use Cases
- Microservices Communication
- Real-time Data Processing
- Distributed Systems
- Task Distribution
Example
In this example, the publisher sends messages to a specified port, and the subscriber receives those messages, illustrating the basic PUB/SUB pattern that ZeroMQ supports.
Cpanel and PHP
In CPANEL under PHP Selector under PHP Extensions select ZMQ.
server.php
// server.php
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_REP);
// Bind the socket to the server's shared IP address and a specific port
$socket->bind("tcp://your-ip:5555");
while (true) {
// Wait for the next request from the client
$message = $socket->recv();
echo "Received request: $message\n";
// Send a reply back to the client
$socket->send("World");
}
Start
/server.php in one tab.
client.php
// client.php
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_REQ);
// Connect to the server using the shared IP address
$socket->connect("tcp://your-ip:5555");
// Send a request to the server
$socket->send("Hello");
// Get the reply from the server
$message = $socket->recv();
echo "Received reply: $message\n";
Target
/client.php with your browser and you should see: