【linux + lighttpd + php + zeromq】之实战训练二
三、实践 2. zeromq mdp(Majordomo Protocol)模式测试 说明: 1) zeromq mdp模式大家可以到zeromq官网的guide自己学习,不在此处赘述。 不过mdp模式的结构还是要提一下,具体如下图: 2) 测试环境说明( 默认您已经安装了zmq库和czmq库,已经php增加了zm
三、实践
2. zeromq mdp(Majordomo Protocol)模式测试
说明:
1) zeromq mdp模式大家可以到zeromq官网的guide自己学习,不在此处赘述。
不过mdp模式的结构还是要提一下,具体如下图:
2) 测试环境说明(默认您已经安装了zmq库和czmq库,已经php增加了zmq组件。)
根据mdp模式的架构,分成三部分:
a) client:php实现
b) broker:C实现
c) worker:C实现
客户端代码:mdclient.php
版权说明: 此代码是ZMQ官网测试代码,可能做了一点修改;
在此处就不将所有代码贴出来了,其实都是zmq官网上的测试代码,经过一些简单的修改;
如果哪位同学有需要,或测试过程中遇到什么困难,可以直接评论,我们一起讨论。
Copy after login<?php /* * Majordomo Protocol client example * Uses the mdcli API to hide all MDP aspects * * @author Ian Barber <ian(dot)barber(at)gmail(dot)com> */ include_once 'mdcliapi.php'; $verbose = $_SERVER['argc'] > 1 && $_SERVER['argv'][1] == '-v'; $session = new MDCli("tcp://localhost:5555", $verbose); for ($count = 0; $count body_set("Hello world from php client"); $reply = $session->send("echo", $request); if (!$reply) { break; // Interrupt or failure } } printf ("%d requests/replies processed", $count); echo PHP_EOL; ?>Copy after loginCopy after loginCopy after login
测试结果(client):
<img src="/static/imghw/default1.png" data-src="/inc/test.jsp?url=http%3A%2F%2Fimg.blog.csdn.net%2F20131123133308171%3Fwatermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQvYW1pbmdfbmo%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast&refer=http%3A%2F%2Fblog.csdn.net%2Fu012916394%2Farticle%2Fdetails%2F16898843" class="lazy" alt="【linux + lighttpd + php + zeromq】之实战训练二" >Copy after login
测试结果(broker):
<img src="/static/imghw/default1.png" data-src="/inc/test.jsp?url=http%3A%2F%2Fimg.blog.csdn.net%2F20131123133324828%3Fwatermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQvYW1pbmdfbmo%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast&refer=http%3A%2F%2Fblog.csdn.net%2Fu012916394%2Farticle%2Fdetails%2F16898843" class="lazy" alt="【linux + lighttpd + php + zeromq】之实战训练二" >Copy after login
测试结果(worker):
<img src="/static/imghw/default1.png" data-src="/inc/test.jsp?url=http%3A%2F%2Fimg.blog.csdn.net%2F20131123133443062%3Fwatermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQvYW1pbmdfbmo%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast&refer=http%3A%2F%2Fblog.csdn.net%2Fu012916394%2Farticle%2Fdetails%2F16898843" class="lazy" alt="【linux + lighttpd + php + zeromq】之实战训练二" >Copy after login
测试结果分析:
1)从client(php)发送字符串“Hello world from php client”;
2)经过broker路由(broker没有打开调试开关,所以看不到打印过程);
3)最终发送到worker。
测试过程遇到的问题:
上面的示例是client仅发送,没有接收。如果使用mdclient2.php那套代码测试,worker和broker使用c,且发送多帧数据时,你会发现client解析会出现错误。经排查这是由于php client在接收时少解析一个帧。
四、总结
【linux + lighttpd + php + zeromq】这套架构,从环境搭建,到两个小例子测试都已经完成。相信如果自己实践过的同学,应该算入门了。如果想将此架构应用到实际的项目中,可能还有不少路要走。希望遇到问题的同学,能在此博客一起讨论,交流。
没有目标或梦想的生活很可怕,很无聊!
你明天的生活,是由你今天决定的!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.
