Php 开发笔记相关

Summary: Author: 张亚飞 | 阅读时间: 1 minute read | Published: 2016-03-14
Filed under Categories: LinuxTags: Note,

Php 开发笔记相关


添加 browscap 插件 - 无需修改 php.ini

2016/05/14 09:51:23 [error] 32417#32417: *4 FastCGI sent in stderr: 
"PHP message: PHP Warning:  get_browser(): browscap ini directive not set in /data/home/coam/ServerCoam/LogisticsPlatform/applications/controllers/ControllerBase.php on line 25
  • 下面开始测试安装 browscap 插件
coam@coam:~$ cd /ServerCoam/Home/applications/plugins
coam@coam:~/ServerCoam/Home/applications/plugins$ git clone https://github.com/browscap/browscap-php BrowsCap
coam@coam:~/ServerCoam/Home/applications/plugins$ cd BrowsCap
coam@coam:~/ServerCoam/Home/applications/plugins$ composer install
  • 必须通过命令自动下载 browscap.ini
coam@coam:~/ServerCoam/Home/applications/plugins/BrowsCap$ bin/browscap-php browscap:fetch
coam@coam:~/ServerCoam/Home/applications/plugins/BrowsCap$ bin/browscap-php browscap:convert

否则 通过 $this->BrowsCap->getBrowser(); 获取的信息都是空白

  • 通过命令自动更新 browscap.ini
sudo ./bin/browscap-php browscap:update
  • 引入文件测试:
<? php
require 'vendor/autoload.php';

// The Browscap class is in the BrowscapPHP namespace, so import it
use BrowscapPHP\Browscap;

// Create a new Browscap object (loads or creates the cache)
$bc = new Browscap();

// Get information about the current browser's user agent
$current_browser = $bc->getBrowser();

实测性能与php.ini加载的方式没有什么性能提升,应把原来的php.ini中对 browscap 的 配置注释掉

性能有巨大的提升,并且不用修改配置php.ini文件


使用 browscap.ini 让php识别客户端浏览器 – 旧版,性能不高,已弃用

  • 首先添加 browscap 到 php.ini
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
print_r($browser);
?>

Comments

  • 牧马人 says: 2019-09-14 08:36:19

    江山代有才人出,各领风骚数百年.

Cor-Ethan, the beverage → www.iirii.com