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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题