0

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\n";'
Hello

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

****VS the below****

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

time php -r 'echo "Hello\n";'
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 ?

redbaron
  • 43
  • 5

1 Answers1

0

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
lafor
  • 12,472
  • 4
  • 32
  • 35
  • If the entire browscap.ini is loaded on php startup, then calls to get_browser() should be quick - which is 'not' what is observed & seemingly indicates that its because of a file parsing lookup. – redbaron Aug 11 '15 at 23:24
  • But the results do seem to indicate that browscap.ini is indeed worked on in some way during the php startup. If its validating the file's existence etc. then it seems ok but if it is loading the entire browscap.ini file then that is excessive & unnecessary. – redbaron Aug 11 '15 at 23:26