dp610807 2011-02-23 22:04
浏览 66
已采纳

APC缓存文件与缓存变量

Say I have a file a.php which only contains a large array:

$client = array(
    "a" => 123,
    "b" => 124,
    ...
 );

APC caches the file a.php but what does that mean exactly? It caches the opcode for the assignment only? Does it actually cache the mapping itself? Or do I need to explicitly put that in the APC cache?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongtan5558 2011-02-23 22:21
    关注

    APC caches a PHP file in byte code. This is a faster intermediary between human readable code and what the interpreter ends up executing. This is analogous to compiling a C/C++ file into a binary. An array compiled in this fashion will load quicker than if you read it form file.

    Accessing an element in an associative array in php is constant time O(1) in Big-O. Adding an element is also O(1). By and large its best to store such arrays in the database because it uses less memory and is much more flexible. Keep in mind that every browser that visits this application is going to have its own copy of this array, where as if you use a database there would be only one copy. For instance if you want to look up a key based on its value you'll have to iterate over it which is O(n) (which is slow), the use of a database will be much faster.

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

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错