dongyiyu882684 2012-01-22 22:34
浏览 49
已采纳

PHP:只是安装APC足以启用缓存,还是我还需要更改我的代码?

A very noob question here.

I just installed APC and when I go to the monitoring page (apc.php) and click on the "System Cache Entries" tab I can see a lot of pages on that list after browsing my app that's hosted on the server. To test I restarted apache and all the cache entries were gone but as soon as I started browsing more pages on my app again they started appearing on that list.

I didn't make any changes to my code, so is this all I have to do to enable optcode caching? Or are changes to my code also necessary?

I ask because my app is using codeigniter and there is a page in the codeigniter docs on caching docs that describes code changes:

http://codeigniter.com/user_guide/libraries/caching.html

  • 写回答

2条回答 默认 最新

  • duanre4421 2012-01-22 22:45
    关注

    APC stores opcode caches as they are parsed. As you have already discovered the caches only persist as long as apache remains open. But when an opcode cache is missing for a page that is requested, APC will store it for as long as Apache remains running. However, opcode caches are only half the battle. While it is true you will receive a speed increase from caching opcode, a lot of time in PHP is lost to file input/output and socket communications (ie. database queries). As long as you can be sure that your script is the only resource which will be modifying the database or a file, you can safely caching database query results or file contents so that each request doesn't need to touch the filesystem or database layer. The logic for this uses some APC functions:

    if(apc_exists('some_database_value')) {
        $value = apc_fetch('some_database_value');
    } else {
        //Query db for value, store in $value
        apc_store('some_database_value', $value);
    }
    

    The only disadvantage to this solution is if you need to modify any cached resource outside of the PHP script, you will need to clear the APC cache from the CLI.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作