Ajax request for Redis subscription operation no return

Source: Internet
Author: User
There is a button on the interface, click to send an AJAX request to the background, the requested file content:

redis.php:

ini_set('default_socket_timeout',25);$redis = new Redis();$conn = $redis->connect('127.0.0.1','6379');if($conn){    $redis->subscribe(array('XGD'),'ckr');}else{    echo '本地Redis无法连接!';    exit;}function ckr($instance,$channel,$msg){    echo $msg;}

Then in the server simulation to the channel XGD Post message, publish the operation code:

publish.php:

 $redis = new Redis (); $conn = $redis->connect (' 127.0.0.1 ',    ' 6379 '); if ($conn) {$i = 0;        while (true) {sleep (1);        $i + +;        $respose [' id '] = uniqid ();        $respose [' v_ltl_status '] = uniqid ();        $respose [' ltl_time '] = uniqid ();        $respose [' ltl_reckon '] = uniqid ();        $respose [' ltl_cardno '] = uniqid ();        $respose [' card_type '] = uniqid ();        $respose [' card_name '] = uniqid ();        $respose [' ltl_cardflag '] = uniqid ();        $respose [' rsd_bicc '] = uniqid ();                $respose [' v_ltl_type '] = uniqid ();                $res _json = json_encode (Array (' result ' = = $respose));        $redis->publish (' xgd ', $res _json);    Echo ' data has been released '. $i. ' 
'; }}else{Echo ' local redis cannot connect! '; Exit;}

The server uses Centos6.5 to run publish.php with PHP commands on the service side.
Enter the local REDIS-CLI command line at the same time, execute the command: Subscribe XGD,
The interface will be circulated to the subscription channel content, re-open a command terminal, the PHP command to execute redis.php, the command line also appeared on the subscription channel published information, the problem is:
Ajax requests on the Web front end always run timeouts, and no results are returned. I do not know why, but also ask the great God enlighten you.

The AJAX code is:

function loadResult(){        //$.pdialog.open("__URL__/getRedisInfo",'operate','操作结果',{'width':'700','height':'400','mask':true});                var dt = new Date();        var ts = dt.getTime();        $.ajax({            cache : false,            type : 'post',            url : '/redis.php',            global: false,            dataType : 'json',            async : true,            data:{time:ts},            timeout:1000,            success:function(data){                $(".redis").html($(".redis").html()+data.result);            },            complete:function(){                loadResult();            }        })            }

(The project uses THINKPHP+DWZ)

================================================================

Reply content:

There is a button on the interface, click to send an AJAX request to the background, the requested file content:

redis.php:

ini_set('default_socket_timeout',25);$redis = new Redis();$conn = $redis->connect('127.0.0.1','6379');if($conn){    $redis->subscribe(array('XGD'),'ckr');}else{    echo '本地Redis无法连接!';    exit;}function ckr($instance,$channel,$msg){    echo $msg;}

Then in the server simulation to the channel XGD Post message, publish the operation code:

publish.php:

 $redis = new Redis (); $conn = $redis->connect (' 127.0.0.1 ',    ' 6379 '); if ($conn) {$i = 0;        while (true) {sleep (1);        $i + +;        $respose [' id '] = uniqid ();        $respose [' v_ltl_status '] = uniqid ();        $respose [' ltl_time '] = uniqid ();        $respose [' ltl_reckon '] = uniqid ();        $respose [' ltl_cardno '] = uniqid ();        $respose [' card_type '] = uniqid ();        $respose [' card_name '] = uniqid ();        $respose [' ltl_cardflag '] = uniqid ();        $respose [' rsd_bicc '] = uniqid ();                $respose [' v_ltl_type '] = uniqid ();                $res _json = json_encode (Array (' result ' = = $respose));        $redis->publish (' xgd ', $res _json);    Echo ' data has been released '. $i. ' 
'; }}else{Echo ' local redis cannot connect! '; Exit;}

The server uses Centos6.5 to run publish.php with PHP commands on the service side.
Enter the local REDIS-CLI command line at the same time, execute the command: Subscribe XGD,
The interface will be circulated to the subscription channel content, re-open a command terminal, the PHP command to execute redis.php, the command line also appeared on the subscription channel published information, the problem is:
Ajax requests on the Web front end always run timeouts, and no results are returned. I do not know why, but also ask the great God enlighten you.

The AJAX code is:

function loadResult(){        //$.pdialog.open("__URL__/getRedisInfo",'operate','操作结果',{'width':'700','height':'400','mask':true});                var dt = new Date();        var ts = dt.getTime();        $.ajax({            cache : false,            type : 'post',            url : '/redis.php',            global: false,            dataType : 'json',            async : true,            data:{time:ts},            timeout:1000,            success:function(data){                $(".redis").html($(".redis").html()+data.result);            },            complete:function(){                loadResult();            }        })            }

(The project uses THINKPHP+DWZ)

================================================================

Blocking mode, does not end, so the timeout, you in callback inside exit look?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.