dongmangji0950 2015-06-16 09:56
浏览 57
已采纳

在Codeigniter中使用页面或数据库缓存进行多个ajax调用

I'm building a application/game in Codeigniter 3. There is one application running on a beamer in front of a classroom, and other users can play via there mobile. The application needs to send json to the players. It has to be done without any services like Pusher or socket.io, because i can't install anything on the server, and there is no budget for external service.

So i have some Javascript running on the users:

setInterval(function(){
    $.getJSON( "ajax/data/json", { 'id': id }, function( data ){
        // Do stuff with the data if its available
    });
}, 1000);

On the application i have something like this:

public function json()
{
    $this->load->model('data_model');
    $data = $this->data_model->get_json($this->input->get('id'));
    echo json_encode($data);
}

My only worry is the game is played on many locations at the same time. Can i use Codeigniters 'Page Caching' or 'Database Cashing' to prevent too many database requests, and what is the best way to implement this? Or is there any other solution to prevent this?

  • 写回答

1条回答 默认 最新

  • dsqnonh2763 2015-06-16 10:57
    关注

    I think this is a pretty tough question because there are so many possibilities to get a solution for this problem

    In my opinion the biggest speed up thing is the use of a key / value storage server as a "between" server (db -> key / value storage -> output) i've installed REDIS on almost all CI applications because it is so fast

    if you've access to your server, i strongly recommend to install a service like redis.

    For example I took a quick look:

    On a I5-2500 local system with 16 GB Ram i can execute 10.000 Queries in about 1 second

    And especially in an ajax build up setup you have to be careful - because your request shouldn't take longer than 100ms (approx!)

    Here are a few links to make a picture out of this:

    PHPredis on Github

    Redis Documentation

    if you don't have any access to your server you should try to use the file based caching. For further information take a look here (CI Documentation about Caching)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#vscode#的问题:ESP32开发板对接MQTT实现小灯泡的开关
  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏