There is a button on the interface, click to send an Ajax request to the background, the requested file content: redis. php: {code ...} then, the server simulates the release of a message to the channel XGD and publishes the operation code: Publish. php: {code ...} the server uses Centos6.5, and the server uses the php Command to run pu... 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 ('2017. 127. 0.0.1 ', '000000'); if ($ conn) {$ redis-> subscribe (array ('xgd'), 'ckr ');} else {echo 'local Redis cannot be connected! '; Exit;} function ckr ($ instance, $ channel, $ msg) {echo $ msg ;}
Then, the server sends a message to the channel XGD and publishes the operation code:
Publish. php:
$ Redis = new Redis (); $ conn = $ redis-> connect ('2017. 0.0.1 ', '000000'); 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 published '. $ I.'
';}} Else {echo' Local Redis cannot be connected! '; Exit ;}
The server uses Centos6.5 and runs publish. php with the php Command on the server,
At the same time, enter the local redis-cli command line and execute the command: subscribe XGD,
The page shows the content published by the subscription channel cyclically. restart a command terminal and run redis. php with the php Command. The message published by the subscription channel also appears on the command line. The problem is:
Ajax requests on the Web Front end always run out of time and no results are returned. I don't know why. Please kindly enlighten me.
The Ajax code is:
Function loadResult () {// $. pdialog. open ("/index. php/Article/getRedisInfo ", 'operate', 'Operation result', {'width': '000000', 'height': '000000', '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 "2.16.html ($ (". redis "2.16.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 ('2017. 127. 0.0.1 ', '000000'); if ($ conn) {$ redis-> subscribe (array ('xgd'), 'ckr ');} else {echo 'local Redis cannot be connected! '; Exit;} function ckr ($ instance, $ channel, $ msg) {echo $ msg ;}
Then, the server sends a message to the channel XGD and publishes the operation code:
Publish. php:
$ Redis = new Redis (); $ conn = $ redis-> connect ('2017. 0.0.1 ', '000000'); 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 published '. $ I.'
';}} Else {echo' Local Redis cannot be connected! '; Exit ;}
The server uses Centos6.5 and runs publish. php with the php Command on the server,
At the same time, enter the local redis-cli command line and execute the command: subscribe XGD,
The page shows the content published by the subscription channel cyclically. restart a command terminal and run redis. php with the php Command. The message published by the subscription channel also appears on the command line. The problem is:
Ajax requests on the Web Front end always run out of time and no results are returned. I don't know why. Please kindly enlighten me.
The Ajax code is:
Function loadResult () {// $. pdialog. open ("/index. php/Article/getRedisInfo ", 'operate', 'Operation result', {'width': '000000', 'height': '000000', '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 "2.16.html ($ (". redis "2.16.html () + data. result) ;}, complete: function () {loadResult ();}})}
(The project uses Thinkphp + DWZ)
========================================================== ======================================
The blocking mode does not end, so it times out. Do you need to exit in callback?