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?