每次添加该文件时,该文件都会被标记吗? [英] Is the same file tokenized every time I include it?

查看:76
本文介绍了每次添加该文件时,该文件都会被标记吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于PHP解析引擎的.

This question is about the PHP parsing engine.

当我在一个运行时中多次包含文件时,PHP是否每次都会对该文件进行标记化,还是保留一个缓存并仅在随后的包含项上运行编译后的代码?

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?

更多详细信息:我没有使用外部缓存机制,而是在同一请求中多次包含相同文件.

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.

我要包含的文件包含程序代码.我希望每次include()都执行它,我很好奇PHP是否出于速度原因在内部跟踪文件的标记化版本.

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.

推荐答案

默认情况下,每次(确实)包含该文件时,即使是在同一php实例中,都将对该文件进行解析. 但是有一些操作码缓存,例如 apc

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

(好的,证据不充分.PHP可以检查文件的mtime是否已更改.我认为apc可以做什么.但是没有缓存,PHP确实没有)

(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)

这篇关于每次添加该文件时,该文件都会被标记吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆