Search code examples
phpjavascriptuser-agentbrowser-detectionbrowscap

get_browser slowing down page load, any alternative?


I have used PHP's get_browser function for quite some time now and have never really noticed any lag on any of my websites. However, recently I noticed that one of my sites was taking a second or so more to load at the server end than it should take. I commented out the get_browser function and the page loaded instantly.

Could this be to do with my server or is the get_browser function known to be slow? The website is the only website I have that is running on a windows server, could this be the issue? Or could this be to do with my browscap.ini file (this is updated everyday from http://browsers.garykeith.com)?

If there is nothing I can do to speed up the get_browser function, are there any alternatives to it? I need to reliably collect the following information about the browser:

  1. What browser it is, i.e. Chrome, IE, Safari etc
  2. What version it is (in full), i.e 10.1 etc
  3. Whether it is a crawler or a bot

I am not aware of any other methods of gathering this information from the user agent, would it be better to use javascript (I would rather not as I need the values server side)?


Solution

  • I also experiences about a 5s delay when using get_browser so i also looked for another solution.

    What works great and will surely be up to date for a long time is a lib in piwik: