【编者按】网学网PHP频道为大家收集整理了“提高define性能的php扩展hidef的安装和使用“提供大家参考,希望对大家有所帮助!
官网:/uploadfile/201306/22/1911336367.gif" border=0>
-----------------------------------------------------------------------------
附:
如果使用了APC,apc提供了定义常量的方法。apc_define_constants和apc_load_constants。apc_define_constants将常量转为数组存到一个user cache中。虽然把常量存在了内存中,但每次PHP请求时,仍然需要读cache,分别定义,因此也不会有什么明显的性能提升。我测试了下定义25个常量,使用apc的函数比直接定义常量快了0.01ms。
这样使用:
if(!apc_load_constants(''defined'')) {
$constants = array(
''HX'' => TRUE,
''D_BUG'' => 1
);
apc_define_constants(''defined'', $constants);
}
define() is notoriously slow. Since the main benefit of APC is to increase the performance of scripts/applications, this mechanism is provided to streamline the process of mass constant definition. However, this function does not perform as well as anticipated.
For a better-performing solution, try the hidef extension from PECL.
APC的文档中推荐使用hidef。