English 中文(简体)
FuelPHP - Agent::is_mobile() memory inquiry
原标题:
  • 时间:2011-07-18 15:44:07
  •  标签:
  • fuelphp

I been testing is_mobile():

if (Agent::is_mobile())
{
    $content = View::factory( mobileviewname );
}
else
{
    $content = View::factory( standardviewname );
}

PHP 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.





相关问题
How do you work with a single ORM query result in FuelPHP?

I have a query that is returning a single result and I m wondering if there s a way to access the properties of that result without having to loop through it since I am limiting it to a single result. ...

Getting FuelPHP observers to use MySQL datetimes

I was trying to get the FuelPHP ORM Observers to use MySQL datetimes rather than unix timestamps, however I can t figure out how to use the code provided in the docs. They provide this code: Orm...

OOP used in FuelPHP

I m trying to undestand how FuelPHP was written.. And since I don t know OOP much, I m puzzled when this class: https://github.com/fuel/core/blob/master/classes/date.php Here are methods that I don t ...

FuelPHP - Agent::is_mobile() memory inquiry

I been testing is_mobile(): if (Agent::is_mobile()) { $content = View::factory( mobileviewname ); } else { $content = View::factory( standardviewname ); } PHP profiler reports it taking up ...

FuelPHP Assets in subfolders

Is it possible to use Assets to include files that are in sub folders? Example: [base_url] /assets/css/pepper-grinder/jquery-ui-1.8.11.custom.min.css

identity conditional "===" , performance, and conversion

I ve always came away from stackoverflow answers and any reading I ve done that "===" is superior to "==" because uses a more strict comparison, and you do not waste resources converting value types ...

Fuelphp Asset:: error

Just testing out Fuelphp.. was wondering if anyone is aware of the issue with Asset:: call I implemented it in a template and got an error ( error view : url ) thanks ps: I guess i need to set Asset:...

How do I insert a NULL value in FUEL / ActiveRecord

Brief forward: I tried to ask this on the FUEL forums, but every time I try and register, their forum says "Failed sending activation email" and I can t log in or reset my account. So hopefully folks ...

热门标签