doulu8341 2009-04-30 00:22
浏览 33
已采纳

每次包含它时都会对同一文件进行标记吗?

This question is about the PHP parsing engine.

When I include a file multiple times in a single runtime, does PHP tokenize it every time or does it keep a cache and just run the compiled code on subsequent inclusions?

EDIT: More details: I am not using an external caching mechanism and I am dealing with the same file being included multiple times during the same request.

EDIT 2: The file I'm trying to include contains procedural code. I want it to be executed every time I include() it, I am just curious if PHP internally keeps track of the tokenized version of the file for speed reasons.

  • 写回答

4条回答 默认 最新

  • duanpa1980 2009-04-30 00:32
    关注

    By default the file is parsed every time it is (really) included, even within the same php instance. But there are opcode caches like e.g. apc

    <?php
    $i = 'include_test.php';
    file_put_contents($i, '<?php $x = 1;'); include $i; echo $x, ' ';
    file_put_contents($i, '<?php $x = 2;'); include $i; echo $x, ' '
    1 2
    (ok, weak proof. PHP could check whether the file's mtime has changed. And that what apc does, I think. But without a cache PHP really doesn't)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染