duan0424 2014-07-15 10:12
浏览 8
已采纳

允许的内存大小在Browscap中耗尽

I have downloaded the library browscap version 2.0 and added this code

$browscap = new Browscap('/tmp');
$browscap->doAutoUpdate = false;
$current_browser = $browscap->getBrowser();

The problem is when I am trying to get information about the current browser I'll have an error

Allowed memory size of 268435456 bytes exhausted (tried to allocate 281 bytes) in ....phpbrowscap-2.0/src/phpbrowscap/Browscap.php on line 677

I do not want to increase the memory because I will be losing performance since my code is executed on every load page. So I tried debugging the code, I noticed that he is checking a lot of browsers. There is a lot of values in $tmp_user_agents and he is looping over this variable.

Is there anyway to get the functionality of this library without taking too much time? Or am I missing something in how it works

  • 写回答

2条回答 默认 最新

  • duanquanzhi5560 2014-07-15 13:44
    关注

    Well Browscap has a very very huge database and to load that (and iterate over it) on EVERY single page hit is of course not very efficient. The "ini" file I downloaded on their website has 7.5MB!!! That PHP runs out of memory is easy to understand. I would not recommend to use this library in this case.

    I only checked their website and the resource file - not the code - but it seems as if they only look for the User-Agent String to verify the browser (which is very easy to fake by the way).

    Have you ever looked at this PHP function: http://php.net/manual/de/function.get-browser.php Enough output for your needs?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动