Precise and high-speed UA identification in PHP

Source: Internet
Author: User
PHP accurately and quickly identifies UA: user-agent, which can be obtained in the server variables provided by PHP. What is the purpose of user-agent identification? 1. what browser is it? This is no longer required. The HACK of CSS can help you correctly render the image in a browser. 2. browser type: this is definitely required for precise and fast UA identification in PHP

UA: the user-agent is available in the server variables provided by PHP. What is the purpose of user-agent identification?

1. what browser is it? This is no longer required. The HACK of CSS can help you correctly render the image in a browser.

2. browser type: this is mandatory. what we want most is to know whether it is in a PC or a mobile phone. in this way, we can select different pages.

3. user-agent: On the surface, it is the same concept as the browser type, but it is actually different. The user-agent has a wider range than the browser type. Because, visitors not only have browsers, but also applications, search robots, and spam websites to capture information. For Spam websites that come to capture information, of course, many of them are disguised. to deal with it, it is not handled in UA identification, but in IP routing.

In MVC mode, the most important reason for UA routing is to make the client request to display the correct page.

However, PHP does not have good functions, or is scalable and can be maintained by a third-party open-source, which can be used to quickly identify UA.

Although the get_browser function is of the C language level, the INI files related to it need to be downloaded in real time, and a large INI file of several hundred kb should be searched for the correct UA. then, the corresponding results are calculated based on different algorithms. when the efficiency is high, of course, the download speed is not good, or the process is too large, the machine memory is tight and the speed will immediately decrease. This is a tragedy.

?

The best practice is to completely split all UA strings, and we will find that some strings must be ROBOT proprietary and some strings must be MOBILE proprietary. As a result, to make a CSV, the current data is only a file with less than 1000 records in two fields. The file size is reduced to 20 kB. The data to be processed is reduced by about 25 times. The speed is 20 times faster than the original speed, and more than 200 times faster than the original speed.

?

Why? How many times does it take to find 1000 records in half? In addition, if 1000 rows of records are not found in 20 KB text, it is much faster than searching for more than 400 rows of configuration records that cannot be searched in more than 20 thousand KB files.

?

?

?

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.