承接 dsentker/phpinsights 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dsentker/phpinsights

最新稳定版本:0.2.2

Composer 安装命令:

composer require dsentker/phpinsights

包简介

A php wrapper for Googles page speed insights

README 文档

README

An easy-to-use API Wrapper for Googles PageSpeed Insights. The JSON response is mapped to objects for an headache-free usage.

Installation

  1. Get an api key from the google developer console for Page Speed Insights.
  2. composer require dsentker/phpinsights
  3. Have fun with this library.

Usage

Simple Usage

$url = 'http://example.com';

$caller = new \PhpInsights\InsightsCaller('your-google-api-key-here', 'de');
$response = $caller->getResponse($url, \PhpInsights\InsightsCaller::STRATEGY_MOBILE);
$result = $response->getMappedResult();

var_dump($result->getSpeedScore()); // 100 
var_dump($result->getUsabilityScore()); // 100 

Using Concurrent Requests

$urls = array(
    'http://example.com', 
    'http://example2.com', 
    'http://example3.com'
);

$caller = new \PhpInsights\InsightsCaller('your-google-api-key-here', 'fr');
$responses = $caller->getResponses($urls, \PhpInsights\InsightsCaller::STRATEGY_MOBILE);

foreach ($responses as $url => $response) {
    $result = $response->getMappedResult();

    var_dump($result->getSpeedScore()); // 100 
    var_dump($result->getUsabilityScore()); // 100 
}

Result details

Full result

/** @var \PhpInsights\Result\InsightsResult $result */
foreach($result->getFormattedResults()->getRuleResults() as $rule => $ruleResult) {
    
    /*
     * If the rule impact is zero, it means that the website has passed the test.
     */
    if($ruleResult->getRuleImpact() > 0) {
    
        var_dump($rule); // AvoidLandingPageRedirects
        var_dump($ruleResult->getLocalizedRuleName()); // "Zielseiten-Weiterleitungen vermeiden"
        
        /*
         * The getDetails() method is a wrapper to get the `summary` field as well as `Urlblocks` data. You
         * can use $ruleResult->getUrlBlocks() and $ruleResult->getSummary() instead. 
         */
        foreach($ruleResult->getDetails() as $block) {
            var_dump($block->toString()); // "Auf Ihrer Seite sind keine Weiterleitungen vorhanden"
        }
    
    }
    
}

Result details by Rule group

/** @var \PhpInsights\Result\InsightsResult $result */
foreach($result->getFormattedResults()->getRuleResultsByGroup(RuleGroup::GROUP_SPEED) as $rule => $ruleResult) {
    $ruleResult->getSummary()->toString();
}

Screenshot

print $result->screenshot->getImageHtml(); // html image element
print $result->screenshot->getData(); // base64 screenshot representation 

Testing

$ phpunit --bootstrap "path/to/phpinsights/src/autoload.php"

Credits

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub.

ToDo

  • Write more tests
  • Improve my english skills

External Libraries

This library depends on JsonMapper by cweiske to map json fields to php objects and Guzzle (surprise!).

Copyright and license

PhpInsights is licensed for use under the MIT License (MIT). Please see LICENSE for more information.

统计信息

  • 总下载量: 18.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 114
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 114
  • Watchers: 3
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-01-11