handsetdetection/php-apikit
最新稳定版本:4.1.13
Composer 安装命令:
composer require handsetdetection/php-apikit
包简介
A library for stand alone or web service device detection, using HandsetDetection.com.
关键字:
README 文档
README
PHP API Kit v4.0, implementing v4.0 of the HandsetDetection API.
API Kits can use our web service or resolve detections locally depending on your configuration.
Installation
Download the package directly from github or use composer.
{
"require": {
"handsetdetection/php-apikit": "4.*"
}
}
Configuration
API Kit configuration files can be downloaded directly from Handset Detection.
- Login to your dashboard
- Click 'Add a Site'
- Configure your new site
- Grab the config file variables for your API Kit (from the site settings)
- Place the variables into the hdconfig.php file
Examples
Instantiate the HD4 object
// Using the default config file
require_once('HD4.php');
$hd = new HandsetDetection\HD4();
OR
// Using a custom config file
require_once('HD4.php');
$hd = new HandsetDetection\HD4('/tmp/myCustomConfigFile.php');
List all vendors
if ($hd->deviceVendors()) {
$data = $hd->getReply();
print_r($data);
} else {
print $hd->getError();
}
List all device models for a vendor (Nokia)
if ($hd->deviceModels('Nokia')) {
$data = $hd->getReply();
print_r($data);
} else {
print $hd->getError();
}
View information for a specific device (Nokia N95)
if ($hd->deviceView('Nokia','N95')) {
$data = $hd->getReply();
print_r($data);
} else {
print $hd->getError();
}
What devices have this attribute ?
if ($hd->deviceWhatHas('network','CDMA')) {
$data = $hd->getReply();
print_r($data);
} else {
print $hd->getError();
}
Basic device detection
This is the most simple detection call - http headers are picked up automatically.
if ($hd->deviceDetect()) {
$tmp = $hd->getReply();
print_r($tmp);
} else {
print $hd->getError();
}
Manually set the http headers (user-agent etc..)
$hd->setDetectVar('user-agent','Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95-3/20.2.011 Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413');
$hd->setDetectVar('x-wap-profile','http://nds1.nds.nokia.com/uaprof/NN95-1r100.xml');
if ($hd->deviceDetect()) {
$tmp = $hd->getReply();
print_r($tmp);
} else {
print $hd->getError();
}
Download the Full Ultimate Edition
Note : Increase the default timeout before downloading the archive.
$hd->setTimeout(500);
if ($hd->deviceFetchArchive()) {
$data = $hd->getRawReply();
echo "Downloaded ".strlen($data)." bytes";
} else {
print $hd->getError();
print $hd->getRawReply();
}
Download the Community Ultimate Edition
$hd->setTimeout(500);
if ($hd->communityFetchArchive()) {
$data = $hd->getRawReply();
echo "Downloaded ".strlen($data)." bytes";
} else {
print $hd->getError();
print $hd->getRawReply();
}
Flexible Caching Options
Version 4.1.* includes APC(u), Memcache, Memcached and Redis caching options. For backwards compatibility if no option is set in the config file then it defaults to APC.
Note : Memcached and Memcached both have a default maximum object size of 1Mb which is too low. We recommend increasing this limit to at least 5Mb with the -I or --max-item-size= options.
Using Memcache
Include a the following cache configuration in your config file. Options represent any cache flags you would like to pass to the memcache::set call. See http://php.net/manual/en/memcache.set.php for more information.
$hdconfig['cache'] = array (
'memcache' => array (
'options' => 0,
'servers' => array(
'localhost' => '11211'
)
)
)
Using Memcached
Include a the following cache configuration in your config file. Options represent cache settings set via the setOption call : See http://php.net/manual/en/memcached.setoption.php for more information. Pass options as $option => $value in the options array.
$hdconfig['cache'] = array (
'memcached' => array(
'options' => array(),
'servers' => array(
array('localhost', '11211'),
)
)
);
If you're using cache connection pooling then pass the pool name as follows :
$hdconfig['cache'] = array (
'memcached' => array(
'pool' => 'mypool',
'options' => array(),
'servers' => array(
array('localhost', '11211'),
)
)
);
Using Predis
From version 4.1.11 we also have Redis as a caching option. Redis caching uses Predis, which you should include via composer. Use a caching config as follows:
$hdconfig['cache'] = array (
'redis' => array (
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379
)
);
Using PHPRedis
From version 4.1.12 we also have PhpRedis as a caching option, which uses the redis.so extension from https://github.com/phpredis/phpredis . connect_method can be connect or pconnect. pconnect connections also support a peristent_id.
Use a caching config as follows:
$hdconfig['cache'] = array (
'phpredis' => array (
'connect_method' => 'pconnect',
'host' => '127.0.0.1',
'port' => 6379,
'timeout' => 2.5,
'persistent_id' => 'x'
)
);
Extra Examples
Additional examples can be found in the examples.php file.
Getting Started with the Free usage tier and Community Edition
After signing up with our service you'll be on a free usage tier which entitles you to 20,000 Cloud detections (web service) per month, and access to our Community Edition for Ultimate (stand alone) detection. The archive for stand alone detection can be downloaded manually however its easiest to configure the API kit with your credentials and let the API kit do the heavy lifting for you. See examples above for how to do this.
Instructions for manually installing the archive are available at v4 API Ultimate Community Edition, Getting Started
Unit testing
Unit tests use phpUnit and can be found in the tests directory.
API Documentation
See the v4 API Documentation.
API Kits
See the Handset Detection GitHub Repo.
Support
Let us know if you have any hassles (hello@handsetdetection.com).
handsetdetection/php-apikit 适用场景与选型建议
handsetdetection/php-apikit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.48k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「detection」 「user-agent」 「device」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 handsetdetection/php-apikit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 handsetdetection/php-apikit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 handsetdetection/php-apikit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Detect user Browser, OS and Device through Browser USER AGENT
Shim repository for phpmd/phpmd
Language detection in PSR-15 middleware
Platine User Agent is a lightweight library for detecting user browser, device, OS, CPU
Official PHP SDK for the IPGeolocation.io IP Location API with single and bulk lookup support.
统计信息
- 总下载量: 8.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 25
- 依赖项目数: 4
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-13