Home > php教程 > php手册 > body text

【linux + lighttpd + php + zeromq】之实战训练二

WBOY
Release: 2016-06-06 19:45:48
Original
1189 people have browsed it

三、实践 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模式的结构还是要提一下,具体如下图:

【linux + lighttpd + php + zeromq】之实战训练二

                  2) 测试环境说明(默认您已经安装了zmq库和czmq库,已经php增加了zmq组件。)

                         根据mdp模式的架构,分成三部分:

                                     a) client:php实现

                                     b) broker:C实现

                                     c) worker:C实现

 

            客户端代码:mdclient.php                

                    版权说明: 此代码是ZMQ官网测试代码,可能做了一点修改;

                                       在此处就不将所有代码贴出来了,其实都是zmq官网上的测试代码,经过一些简单的修改;

                                       如果哪位同学有需要,或测试过程中遇到什么困难,可以直接评论,我们一起讨论。

Copy after login
Copy after login
           
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 login
Copy after login
Copy after login
 
Copy after login
      测试结果(client):
Copy after login

<img  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" alt="【linux + lighttpd + php + zeromq】之实战训练二" >
Copy after login
      测试结果(broker):
Copy after login
<img  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" alt="【linux + lighttpd + php + zeromq】之实战训练二" >
Copy after login
      测试结果(worker):
Copy after login
<img  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" alt="【linux + lighttpd + php + zeromq】之实战训练二" >
Copy after login

     测试结果分析:
Copy after login

         1)从client(php)发送字符串“Hello world from php client”;
Copy after login

         2)经过broker路由(broker没有打开调试开关,所以看不到打印过程);
Copy after login

         3)最终发送到worker。
Copy after login

 

          测试过程遇到的问题:

                 上面的示例是client仅发送,没有接收。如果使用mdclient2.php那套代码测试,worker和broker使用c,且发送多帧数据时,你会发现client解析会出现错误。经排查这是由于php client在接收时少解析一个帧。

 

四、总结

       【linux + lighttpd + php + zeromq】这套架构,从环境搭建,到两个小例子测试都已经完成。相信如果自己实践过的同学,应该算入门了。如果想将此架构应用到实际的项目中,可能还有不少路要走。希望遇到问题的同学,能在此博客一起讨论,交流。

 

【linux + lighttpd + php + zeromq】之实战训练二没有目标或梦想的生活很可怕,很无聊!

【linux + lighttpd + php + zeromq】之实战训练二你明天的生活,是由你今天决定的!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template