DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Fun Is the Glue That Makes Everything Stick, Also the OCP
  • Five Java Books Beginners and Professionals Should Read
  • Conditional Breakpoints: A Guide to Effective Debugging
  • JavaFX Goes Mobile
  1. DZone
  2. Coding
  3. Frameworks
  4. Enqueue Symfony’s Process Components with PHP and ZeroMQ

Enqueue Symfony’s Process Components with PHP and ZeroMQ

Gonzalo Ayuso user avatar by
Gonzalo Ayuso
·
Apr. 09, 13 · Interview
Like (0)
Save
Tweet
Share
6.20K Views

Join the DZone community and get the full member experience.

Join For Free
Today I’d like to play with ZeroMQ. ZeroMQ is a great tool to work with sockets. I will show you the problem that I want to solve: One web application needs to execute background processes but I need to execute those processes in order. Two users cannot execute one process at the same time. OK, if we face this problem we can use Gearman. I’ve written various posts about Gearman (here and here for example). But today I want to play with ZeroMQ.

I’m going to use one great library called React. With react (reactor pattern implementation in PHP) we can do various thing. One of them are ZeroMQ bindings.

In this simple example we are going to build a simple server and client. The client will send to the server one string that the server will enqueue and executes using the Symfony’s Process component.

Here is the client:

<?php
include __DIR__ . '/../vendor/autoload.php';
 
use Zmqlifo\Client;
 
$queue = Client::factory('tcp://127.0.0.1:4444');
echo $queue->run("ls -latr")->getOutput();
echo $queue->run("pwd")->getOutput();

And finally the server:

<?php
include __DIR__ . '/../vendor/autoload.php';
 
use Symfony\Component\Process\Process;
use Zmqlifo\Server;
 
$server = Server::factory('tcp://127.0.0.1:4444');
$server->registerOnMessageCallback(function ($msg) {
    $process = new Process($msg);
    $process->setTimeout(3600);
    $process->run();
    return $process->getOutput();
});
 
$server->run();

You can see the working example here:

you can check the full code of the library in github and Packagist.

PHP ZeroMQ Symfony

Published at DZone with permission of Gonzalo Ayuso, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Fun Is the Glue That Makes Everything Stick, Also the OCP
  • Five Java Books Beginners and Professionals Should Read
  • Conditional Breakpoints: A Guide to Effective Debugging
  • JavaFX Goes Mobile

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: