drf65218 2015-08-11 22:10
浏览 77
已采纳

Browscap.ini PHP启动延迟

I observed that enabling the browscap.ini entry in the php-cli.ini file increases the startup time for php

[browscap]
browscap = /etc/browscap.ini

time php -r 'echo "Hello
";'
Hello

real    0m1.709s
user    0m1.358s
sys 0m0.348s

****VS the below****

[browscap]
;browscap = /etc/browscap.ini

time php -r 'echo "Hello
";'
Hello

real    0m0.041s
user    0m0.029s
sys 0m0.011s

Now I know that php looks up the browscap.ini file when a function like get_browser() is called. I can understand the lag if such a function is used.

I don't think php would be loading the browscap.ini(which can be large) data into memory on each startup. But why the huge delay in php startup ?

Maybe it tries to check if the browscap.ini file exists on every startup or some other validation ? Could not find anything in the php docs.

So why the huge difference in php startup times ?

  • 写回答

1条回答 默认 最新

  • dongwen7187 2015-08-11 23:05
    关注

    PHP loads its entire configuration (including browscap.ini) on startup, which in CLI is every time you invoke php. It doesn't matter if you don't call get_browser() in your script, it doesn't even matter if you give php no script to interpret at all; the browscap will get loaded anyway if the config file says so. The reason the difference in startup time is noticeable, is because typical browscap.ini is usually relatively large.

    Here's a bunch of results from my machine using different sized browscap files and simple php -v:

    • no browscap: 0m0.030s
    • lite_php_browscap.ini (222 KB): 0m0.040s
    • php_browscap.ini (16,301 KB): 0m0.640s
    • full_php_browscap.ini (33,714 KB): 0m1.290s
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮