开发者

FuelPHP - Agent::is_mobile() memory inquiry

I been testing is_mobile():

if (Agent::is_mobile())
{
    $content = View::factory('mobile\viewname');
}
else
{
    $content = View::factory('standard\viewname');
}

PH开发者_如何转开发P profiler reports it taking up 2.25MB (after subtracting not using is_mobile() function in app) to return a true or false.

my browscap.cache file size is 433KB , is there plans to make this function take up less memory to do its checks? right now, I had to remove this function as it was just adding too much memory to my app.


The best solution is to configure PHP to use the browscap file, through php.ini (http://www.php.net/manual/en/misc.configuration.php#ini.browscap), which would allow the Agent class to use get_browser().

If that's not possible, the Agent class allows you to simulate this function, and fetch the browscap file itself. As Jelmer said, you can replace this file by the light version by changing the configured URL.

However, by default this file is only fetched once a week. After fetching it's parsed, optimized, and cached locally. To be able to do a lookup, this cache file needs to be loaded, which can account for the memory usage you see. It's not kept in memory, so you should only see the memory usage if you check memory_get_peak_usage().

The result of a lookup is cached as well, so the next time the same browser comes along, the information is retrieved from cache, and the browscap cache is not loaded.


This isn't really the best place to ask such a specific Fuel question, we have forums for that very reason and you can post issues on Github if you consider something a bug.

That being said, you can copy the agents.php config file to app/config and edit it to use "http://browsers.garykeith.com/stream.asp?Lite_PHP_BrowsCapINI" instead of "http://browsers.garykeith.com/stream.asp?BrowsCapINI", that saves you a little over 50% in filesize. It recognizes fewer browsers though.

This was written by WanWizard, so you'll have to ask him on the forums if you want to know for sure. But as far as I know this is the most reliable way to know more about the user's browser. I will propose to WanWizard to make the lite version the default though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜