Bug #70490 [Com]: get_browser function is very slow

From: Date: Fri, 13 Nov 2015 13:05:19 +0000
Subject: Bug #70490 [Com]: get_browser function is very slow
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197234@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70490&edit=1 ID: 70490 Comment by: dev018 at am-horizon dot com Reported by: webtech at mines-telecom dot fr Summary: get_browser function is very slow Status: Open Type: Bug Package: Performance problem Operating System: OS X 10.10.5 PHP Version: 7.0.0RC3 Block user comment: N Private report: N New Comment: Hi, I have tested your code but every time it's not take more that 40ms. Could you please test it again Previous Comments: ------------------------------------------------------------------------ [2015-11-04 15:16:57] David dot Gausmann at measX dot com Hello there, I detected the get_browser command as the lack of performance on my website today. Then I've found this bug here. Could you please implement a hashmap or something similar for that command? I cannot believe that searching through an ini file needs so much time. You could for example split the search up and delegate it to multiple threads. Here is my example: <?php $dTime1 = microtime(true); $oBrowser = get_browser('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0'); $dTime2 = microtime(true); $oBrowser2 = get_browser('DoesntExist'); $dTime3 = microtime(true); echo sprintf('%.4f', $dTime2 - $dTime1), "<br>"; echo sprintf('%.4f', $dTime3 - $dTime2), "<br>"; ?> Searching for a non-existent entry still requires so much time like the regular search (> 1 second). Kind Regards David Gausmann ------------------------------------------------------------------------ [2015-09-21 15:26:21] webtech at mines-telecom dot fr I'm using php_browscap.ini (16,301 KB), not the full one full_php_browscap.ini (33,714 KB). I've upgraded to PHP7.0.0RC3 and it's the same. Is it better to use the browscap-php library (https://github.com/browscap/browscap-php) as recommended in http://browscap.org/ ? I though it was better to use native PHP... ------------------------------------------------------------------------ [2015-09-19 09:20:58] yohgaki@php.net I think you are using large browscap.ini. Although browscap.ini is cached in memory, the code searching matched entry is not so fast. If database is large, it takes time. (About 2 sec with debug build CLI server & Core i7 4770S using full_php_browscap.ini) http://browscap.org/ Try lite_php_browscap.ini if you need performance. ------------------------------------------------------------------------ [2015-09-14 13:08:41] webtech at mines-telecom dot fr I've added the version number of OS X. ------------------------------------------------------------------------ [2015-09-14 13:06:55] webtech at mines-telecom dot fr Description: ------------ $aBrowserInfos=get_browser(null,true); Test script: --------------- $time_start = microtime(true); $aBrowserInfos=get_browser(null,true); $time_end = microtime(true); $time = $time_end - $time_start; echo "get_browser takes $time sec"; Expected result: ---------------- Less than 50 ms... Actual result: -------------- get_browser takes 3.3583149909973 sec ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70490&edit=1

« previous php.bugs (#197234) next »