duplexmedia/parallel-pagespeed

一个用于并发交互Google PageSpeed API的库。

v2.1.0 2016-10-21 14:12 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:53:19 UTC


README

一个小的PHP模块,以并行方式查询Google的PageSpeed API。

使用方法如下:

use Duplexmedia\PageSpeed\Service;

/**
 * Gets the pagespeed ratings for the given URLs.
 *
 * @param array|string $urls a URL or an array of URLs (you can pass both)
 */
function query_pagespeed($urls) {
    // Create a new PageSpeed client
    $service = new Service();
    
    // Request the pagespeed ratings either synchronous (blocking fashion)...
    $results = $service->query($urls, 'en_US', 'both');
    // ... or asynchronous, using Guzzle Promises (nonblocking fashion)
    $promise = $service->queryAsync($urls, 'en_US', 'both');
    
    // In the asnyc case, you can use the results either by calling
    // ->wait() or by chaining a computation using ->then(...).
    // See https://github.com/guzzle/promises.
}