Home >Backend Development >PHP Tutorial >php中redis subscribe的使用

php中redis subscribe的使用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:26:002216browse

各位大神们。

最近有在搞redis的订阅和分发subscribe,publish。

1.php

function f($redis, $chan, $msg) {      switch($chan) {          case 'chan-1':              echo 1 ;            echo $msg;            break;          case 'chan-2':              echo 2;            echo $msg;            break;         case 'chan-3':            echo 3;          echo $msg;            break;      }  }    $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); 


2.php
$redis->publish('chan-1', 'Hello Word');


我的问题是:我在1.php里面订阅了3个chan,然后在2.php中,向chan-1 中publish数据。
然后浏览器打开1.php一直在转圈圈。然后到timeout为止。

我的问题是:如何在1.php中看到输出的数据?


回复讨论(解决方案)

请问楼上这个问题解决了么,我也遇到这个问题了

subscribe 是阻塞模式的,一直不会结束。你在命令行执行你的第一个脚本就能看到打印的东西

Statement:
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