├── .gitignore ├── .travis.yml ├── LICENSE ├── LICENSE.md ├── README.md ├── build.xml ├── composer.json ├── data └── ca-bundle.crt ├── phpunit.xml ├── src ├── GTMetrixBrowser.php ├── GTMetrixClient.php ├── GTMetrixConfigurationException.php ├── GTMetrixException.php ├── GTMetrixLocation.php └── GTMetrixTest.php └── tests ├── AbstractGTMetrixTest.php └── GTMetrixFunctionalTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | build 3 | composer.lock 4 | 5 | .DS_Store 6 | 7 | # Created by .ignore support plugin (hsz.mobi) 8 | ### Composer template 9 | composer.phar 10 | vendor/ 11 | 12 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file 13 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 14 | # composer.lock 15 | 16 | 17 | ### JetBrains template 18 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion 19 | 20 | *.iml 21 | 22 | ## Directory-based project format: 23 | .idea/ 24 | # if you remove the above rule, at least ignore the following: 25 | 26 | # User-specific stuff: 27 | # .idea/workspace.xml 28 | # .idea/tasks.xml 29 | # .idea/dictionaries 30 | 31 | # Sensitive or high-churn files: 32 | # .idea/dataSources.ids 33 | # .idea/dataSources.xml 34 | # .idea/sqlDataSources.xml 35 | # .idea/dynamic.xml 36 | # .idea/uiDesigner.xml 37 | 38 | # Gradle: 39 | # .idea/gradle.xml 40 | # .idea/libraries 41 | 42 | # Mongo Explorer plugin: 43 | # .idea/mongoSettings.xml 44 | 45 | ## File-based project format: 46 | *.ipr 47 | *.iws 48 | 49 | ## Plugin-specific files: 50 | 51 | # IntelliJ 52 | /out/ 53 | 54 | # mpeltonen/sbt-idea plugin 55 | .idea_modules/ 56 | 57 | # JIRA plugin 58 | atlassian-ide-plugin.xml 59 | 60 | # Crashlytics plugin (for Android Studio and IntelliJ) 61 | com_crashlytics_export_strings.xml 62 | crashlytics.properties 63 | crashlytics-build.properties 64 | 65 | 66 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | os: 4 | - linux 5 | 6 | dist: bionic 7 | 8 | php: 9 | - 8.0 10 | - 7.4 11 | - 7.3 12 | 13 | install: 14 | - composer remove --dev apigen/apigen 15 | - composer install 16 | script: ./vendor/bin/phing tests 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2021 Phil Cook 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2021 Phil Cook 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GTMetrix API client for PHP 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/philcook/gtmetrix/v)](//packagist.org/packages/philcook/gtmetrix) 4 | [![Build Status](https://travis-ci.org/philcook/php-gtmetrix.svg)](https://travis-ci.org/philcook/php-gtmetrix) 5 | [![Total Downloads](https://poser.pugx.org/philcook/gtmetrix/downloads)](//packagist.org/packages/philcook/gtmetrix) 6 | [![License](https://poser.pugx.org/philcook/gtmetrix/license)](//packagist.org/packages/philcook/gtmetrix) 7 | 8 | ## Installing 9 | 10 | This client library can be installed using [composer](https://getcomposer.org/): 11 | 12 | composer require philcook/gtmetrix 13 | 14 | ## Using 15 | 16 | ```php 17 | use LightningStudio\GTMetrixClient\GTMetrixClient; 18 | use LightningStudio\GTMetrixClient\GTMetrixTest; 19 | 20 | $client = new GTMetrixClient(); 21 | $client->setUsername('your@email.com'); 22 | $client->setAPIKey('your-gtmetrix-api-key'); 23 | 24 | $client->getLocations(); 25 | $client->getBrowsers(); 26 | $test = $client->startTest('http://www.example.com/'); 27 | 28 | //Wait for result 29 | while ($test->getState() != GTMetrixTest::STATE_COMPLETED && 30 | $test->getState() != GTMetrixTest::STATE_ERROR) { 31 | $client->getTestStatus($test); 32 | sleep(5); 33 | } 34 | ``` 35 | 36 | ## Update information 37 | 38 | From version 2.0 references to Entrecore have been replace with LightningStudio due to Entrecore no longer existing and therefore avoiding confusion for users. 39 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "philcook/gtmetrix", 3 | "description": "GTMetrix API client for PHP", 4 | "license": "MIT", 5 | "autoload": { 6 | "psr-4": { 7 | "LightningStudio\\GTMetrixClient\\": "src/" 8 | } 9 | }, 10 | "require": { 11 | "php": ">=7.3", 12 | "ext-curl": "*" 13 | }, 14 | "require-dev": { 15 | "phpunit/phpunit": "~9.5", 16 | "apigen/apigen": "~4.1", 17 | "phing/phing": "~2.16" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tests 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/GTMetrixBrowser.php: -------------------------------------------------------------------------------- 1 | id; 45 | } 46 | 47 | /** 48 | * @param string $id 49 | */ 50 | public function setId($id) { 51 | $this->id = $id; 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function getName() { 58 | return $this->name; 59 | } 60 | 61 | /** 62 | * @param string $name 63 | */ 64 | public function setName($name) { 65 | $this->name = $name; 66 | } 67 | 68 | /** 69 | * @return string 70 | */ 71 | public function getPlatform() { 72 | return $this->platform; 73 | } 74 | 75 | /** 76 | * @param string $platform 77 | */ 78 | public function setPlatform($platform) { 79 | $this->platform = $platform; 80 | } 81 | 82 | /** 83 | * @return string 84 | */ 85 | public function getDevice() { 86 | return $this->device; 87 | } 88 | 89 | /** 90 | * @param string $device 91 | */ 92 | public function setDevice($device) { 93 | $this->device = $device; 94 | } 95 | 96 | /** 97 | * @return string 98 | */ 99 | public function getBrowser() { 100 | return $this->browser; 101 | } 102 | 103 | /** 104 | * @param string $browser 105 | */ 106 | public function setBrowser($browser) { 107 | $this->browser = $browser; 108 | } 109 | 110 | /** 111 | * @return array 112 | */ 113 | public function getFeatures() { 114 | return $this->features; 115 | } 116 | 117 | /** 118 | * @param array $features 119 | */ 120 | public function setFeatures($features) { 121 | $this->features = $features; 122 | } 123 | 124 | /** 125 | * @param string $feature 126 | * 127 | * @return bool 128 | */ 129 | public function hasFeature($feature) { 130 | return (\array_search($feature, $this->features) !== false); 131 | } 132 | 133 | /** 134 | * @param array $data 135 | */ 136 | public function fromArray($data) { 137 | $this->setId($data['id']); 138 | $this->setName($data['name']); 139 | $this->setBrowser($data['browser']); 140 | $this->setDevice($data['device']); 141 | 142 | $features = array(); 143 | foreach ($data['features'] as $feature => $supported) { 144 | if ($supported) { 145 | $features[] = $feature; 146 | } 147 | } 148 | $this->setFeatures($features); 149 | $this->setPlatform($data['platform']); 150 | } 151 | 152 | /** 153 | * @return string 154 | */ 155 | public function __toString() { 156 | return $this->getId(); 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /src/GTMetrixClient.php: -------------------------------------------------------------------------------- 1 | setUsername('your@email.com'); 12 | * $client->setAPIKey('your-gtmetrix-api-key'); 13 | * 14 | * $client->getLocations(); 15 | * $client->getBrowsers(); 16 | * $test = $client->startTest(); 17 | * 18 | * //Wait for result 19 | * while ($test->getState() != GTMetrixTest::STATE_COMPLETED && 20 | * $test->getState() != GTMetrixTest::STATE_ERROR) { 21 | * $client->getTestStatus($test); 22 | * sleep(5); 23 | * } 24 | * 25 | */ 26 | class GTMetrixClient { 27 | /** 28 | * API endpoint. Normally you don't need to change this. 29 | * 30 | * @var string 31 | */ 32 | protected $endpoint = 'https://gtmetrix.com/api/0.1'; 33 | 34 | /** 35 | * GTMetrix username 36 | * 37 | * @var string 38 | */ 39 | protected $username = ''; 40 | 41 | /** 42 | * GTMetrix API key. 43 | * 44 | * @var string 45 | * 46 | * @see http://gtmetrix.com/api/ 47 | */ 48 | protected $apiKey = ''; 49 | 50 | /** 51 | * @return string 52 | */ 53 | public function getUsername() { 54 | return $this->username; 55 | } 56 | 57 | /** 58 | * @param string $username 59 | */ 60 | public function setUsername($username) { 61 | $this->username = $username; 62 | } 63 | 64 | /** 65 | * @return string 66 | */ 67 | public function getAPIKey() { 68 | return $this->apiKey; 69 | } 70 | 71 | /** 72 | * @param string $url 73 | * @param array $data 74 | * @param bool $json 75 | * 76 | * @return array|string 77 | * 78 | * @throws GTMetrixConfigurationException 79 | * @throws GTMetrixException 80 | */ 81 | protected function apiCall($url, $data = array(), $json = true) { 82 | if (!$this->username || !$this->apiKey) { 83 | throw new GTMetrixConfigurationException('Username and API key must be set up before using API calls!' . 84 | 'See setUsername() and setAPIKey() for details.'); 85 | } 86 | 87 | $ch = curl_init($this->endpoint . $url); 88 | if (!empty($data)) { 89 | curl_setopt($ch, CURLOPT_POST, count($data)); 90 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); 91 | } 92 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 93 | curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->apiKey); 94 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 95 | curl_setopt($ch, CURLOPT_CAINFO, dirname(__DIR__) . '/data/ca-bundle.crt'); 96 | $result = curl_exec($ch); 97 | $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 98 | $curlErrNo = curl_errno($ch); 99 | $curlError = curl_error($ch); 100 | curl_close ($ch); 101 | 102 | if (!\preg_match('/^(2|3)/', $statusCode)) { 103 | if ($statusCode == 0) { 104 | throw new GTMetrixException('cURL error ' . $curlErrNo . ': ' . $curlError); 105 | } 106 | throw new GTMetrixException('API error ' . $statusCode . ': ' . $result); 107 | } 108 | 109 | if ($json) { 110 | $data = json_decode($result, true); 111 | if (json_last_error()) { 112 | throw new GTMetrixException('Invalid JSON received: ' . json_last_error_msg()); 113 | } 114 | } else { 115 | $data = $result; 116 | } 117 | 118 | return $data; 119 | } 120 | 121 | /** 122 | * @param string $apiKey 123 | */ 124 | public function setAPIKey($apiKey) { 125 | $this->apiKey = $apiKey; 126 | } 127 | 128 | /** 129 | * @return GTMetrixLocation[] 130 | * 131 | * @throws GTMetrixConfigurationException 132 | */ 133 | public function getLocations() { 134 | $result = $this->apiCall('/locations'); 135 | 136 | $locations = array(); 137 | foreach ($result as $locationData) { 138 | $location = new GTMetrixLocation(); 139 | $location->fromArray($locationData); 140 | $locations[] = $location; 141 | } 142 | return $locations; 143 | } 144 | 145 | /** 146 | * @return GTMetrixBrowser[] 147 | * 148 | * @throws GTMetrixConfigurationException 149 | */ 150 | public function getBrowsers() { 151 | $result = $this->apiCall('/browsers'); 152 | 153 | $browsers = array(); 154 | foreach ($result as $browserData) { 155 | $browser = new GTMetrixBrowser(); 156 | $browser->fromArray($browserData); 157 | $browsers[] = $browser; 158 | } 159 | return $browsers; 160 | } 161 | 162 | /** 163 | * @param string $id 164 | * 165 | * @return GTMetrixBrowser 166 | * @throws GTMetrixConfigurationException 167 | * @throws GTMetrixException 168 | */ 169 | public function getBrowser($id) { 170 | $result = $this->apiCall('/browsers/' . urlencode($id)); 171 | $browser = new GTMetrixBrowser(); 172 | $browser->fromArray($result); 173 | return $browser; 174 | } 175 | 176 | /** 177 | * Start a GTMetrix test 178 | * 179 | * @param string $url 180 | * 181 | * @param null|string $location 182 | * @param null|string $browser 183 | * @param null|string $httpUser 184 | * @param null|string $httpPassword 185 | * @param array $xParams 186 | * 187 | * @return GTMetrixTest 188 | * @throws GTMetrixConfigurationException 189 | * @throws GTMetrixException 190 | */ 191 | public function startTest($url, $location = null, $browser = null, $httpUser = null, $httpPassword = null, array $xParams = []) { 192 | 193 | $data = array(); 194 | $data['url'] = $url; 195 | if ($location) { 196 | $data['location'] = $location; 197 | } 198 | if ($browser) { 199 | $data['browser'] = $browser; 200 | } 201 | if ($httpUser) { 202 | $data['login-user'] = $httpUser; 203 | } 204 | if ($httpPassword) { 205 | $data['login-pass'] = $httpPassword; 206 | } 207 | if ($xParams) { 208 | $data = array_merge($data, $xParams); 209 | } 210 | $result = $this->apiCall('/test', $data); 211 | 212 | $test = new GTMetrixTest(); 213 | $test->setId($result['test_id']); 214 | $test->setPollStateUrl($result['poll_state_url']); 215 | 216 | return $test; 217 | } 218 | 219 | /** 220 | * @param GTMetrixTest|string $test GTMetrixTest or test ID. This object will be updated 221 | * 222 | * @return GTMetrixTest 223 | */ 224 | public function getTestStatus($test) { 225 | if ($test instanceof GTMetrixTest) { 226 | $testId = $test->getId(); 227 | } else { 228 | $testId = $test; 229 | $test = new GTMetrixTest(); 230 | $test->setId($testId); 231 | } 232 | 233 | $testStatus = $this->apiCall('/test/' . urlencode($testId)); 234 | $test->setState($testStatus['state']); 235 | $test->setError($testStatus['error']); 236 | if ($test->getState() == GTMetrixTest::STATE_COMPLETED) { 237 | $test->setReportUrl($testStatus['results']['report_url']); 238 | $test->setPagespeedScore($testStatus['results']['pagespeed_score']); 239 | $test->setYslowScore($testStatus['results']['yslow_score']); 240 | $test->setHtmlBytes($testStatus['results']['html_bytes']); 241 | $test->setHtmlLoadTime($testStatus['results']['html_load_time']); 242 | $test->setPageBytes($testStatus['results']['page_bytes']); 243 | $test->setPageLoadTime($testStatus['results']['page_load_time']); 244 | $test->setPageElements($testStatus['results']['page_elements']); 245 | $test->setRedirectDuration($testStatus['results']['redirect_duration']); 246 | $test->setConnectDuration($testStatus['results']['connect_duration']); 247 | $test->setBackendDuration($testStatus['results']['backend_duration']); 248 | $test->setFirstPaintTime($testStatus['results']['first_paint_time']); 249 | $test->setFirstContentfulPaintTime($testStatus['results']['first_contentful_paint_time']); 250 | $test->setDomInteractiveTime($testStatus['results']['dom_interactive_time']); 251 | $test->setDomContentLoadedTime($testStatus['results']['dom_content_loaded_time']); 252 | $test->setDomContentLoadedDuration($testStatus['results']['dom_content_loaded_duration']); 253 | $test->setOnloadTime($testStatus['results']['onload_time']); 254 | $test->setOnloadDuration($testStatus['results']['onload_duration']); 255 | $test->setFullyLoadedTime($testStatus['results']['fully_loaded_time']); 256 | $test->setRumSpeedIndex($testStatus['results']['rum_speed_index']); 257 | $test->setResources($testStatus['resources']); 258 | } 259 | 260 | return $test; 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /src/GTMetrixConfigurationException.php: -------------------------------------------------------------------------------- 1 | id; 33 | } 34 | 35 | /** 36 | * @param string $id 37 | */ 38 | public function setId($id) { 39 | $this->id = $id; 40 | } 41 | 42 | /** 43 | * @return string 44 | */ 45 | public function getName() { 46 | return $this->name; 47 | } 48 | 49 | /** 50 | * @param string $name 51 | */ 52 | public function setName($name) { 53 | $this->name = $name; 54 | } 55 | 56 | /** 57 | * @return boolean 58 | */ 59 | public function isDefault() { 60 | return $this->default; 61 | } 62 | 63 | /** 64 | * @param boolean $default 65 | */ 66 | public function setDefault($default) { 67 | $this->default = $default; 68 | } 69 | 70 | /** 71 | * @return string[] 72 | */ 73 | public function getBrowserIds() { 74 | return $this->browserIds; 75 | } 76 | 77 | /** 78 | * @param string[] $browserIds 79 | */ 80 | public function setBrowserIds($browserIds) { 81 | $this->browserIds = $browserIds; 82 | } 83 | 84 | /** 85 | * @param array $data 86 | */ 87 | public function fromArray($data) { 88 | $this->setId($data['id']); 89 | $this->setName($data['name']); 90 | $this->setDefault($data['default']); 91 | $this->setBrowserIds($data['browsers']); 92 | } 93 | 94 | /** 95 | * @return string 96 | */ 97 | public function __toString() { 98 | return $this->getId(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/GTMetrixTest.php: -------------------------------------------------------------------------------- 1 | id; 148 | } 149 | 150 | /** 151 | * @param string $id 152 | */ 153 | public function setId($id) { 154 | $this->id = $id; 155 | } 156 | 157 | /** 158 | * @return string 159 | */ 160 | public function getPollStateUrl() { 161 | return $this->pollStateUrl; 162 | } 163 | 164 | /** 165 | * @param string $pollStateUrl 166 | */ 167 | public function setPollStateUrl($pollStateUrl) { 168 | $this->pollStateUrl = $pollStateUrl; 169 | } 170 | 171 | /** 172 | * @return string 173 | */ 174 | public function getState() { 175 | return $this->state; 176 | } 177 | 178 | /** 179 | * @param string $state 180 | */ 181 | public function setState($state) { 182 | $this->state = $state; 183 | } 184 | 185 | /** 186 | * @return string 187 | */ 188 | public function getError() { 189 | return $this->error; 190 | } 191 | 192 | /** 193 | * @param string $error 194 | */ 195 | public function setError($error) { 196 | $this->error = $error; 197 | } 198 | 199 | /** 200 | * @return string 201 | */ 202 | public function getReportUrl() { 203 | return $this->reportUrl; 204 | } 205 | 206 | /** 207 | * @param string $reportUrl 208 | */ 209 | public function setReportUrl($reportUrl) { 210 | $this->reportUrl = $reportUrl; 211 | } 212 | 213 | /** 214 | * @return int 215 | */ 216 | public function getPagespeedScore() { 217 | return $this->pagespeedScore; 218 | } 219 | 220 | /** 221 | * @param int $pagespeedScore 222 | */ 223 | public function setPagespeedScore($pagespeedScore) { 224 | $this->pagespeedScore = $pagespeedScore; 225 | } 226 | 227 | /** 228 | * @return int 229 | */ 230 | public function getYslowScore() { 231 | return $this->yslowScore; 232 | } 233 | 234 | /** 235 | * @param int $yslowScore 236 | */ 237 | public function setYslowScore($yslowScore) { 238 | $this->yslowScore = $yslowScore; 239 | } 240 | 241 | /** 242 | * @return int 243 | */ 244 | public function getHtmlBytes() { 245 | return $this->htmlBytes; 246 | } 247 | 248 | /** 249 | * @param int $htmlBytes 250 | */ 251 | public function setHtmlBytes($htmlBytes) { 252 | $this->htmlBytes = $htmlBytes; 253 | } 254 | 255 | /** 256 | * @return int 257 | */ 258 | public function getHtmlLoadTime() { 259 | return $this->htmlLoadTime; 260 | } 261 | 262 | /** 263 | * @param int $htmlLoadTime 264 | */ 265 | public function setHtmlLoadTime($htmlLoadTime) { 266 | $this->htmlLoadTime = $htmlLoadTime; 267 | } 268 | 269 | /** 270 | * @return int 271 | */ 272 | public function getPageBytes() { 273 | return $this->pageBytes; 274 | } 275 | 276 | /** 277 | * @param int $pageBytes 278 | */ 279 | public function setPageBytes($pageBytes) { 280 | $this->pageBytes = $pageBytes; 281 | } 282 | 283 | /** 284 | * @return int 285 | */ 286 | public function getPageLoadTime() { 287 | return $this->pageLoadTime; 288 | } 289 | 290 | /** 291 | * @param int $pageLoadTime 292 | */ 293 | public function setPageLoadTime($pageLoadTime) { 294 | $this->pageLoadTime = $pageLoadTime; 295 | } 296 | 297 | /** 298 | * @return int 299 | */ 300 | public function getPageElements() { 301 | return $this->pageElements; 302 | } 303 | 304 | /** 305 | * @param int $pageElements 306 | */ 307 | public function setPageElements($pageElements) { 308 | $this->pageElements = $pageElements; 309 | } 310 | 311 | /** 312 | * @return int 313 | */ 314 | public function getRedirectDuration() { 315 | return $this->redirectDuration; 316 | } 317 | 318 | /** 319 | * @param int $redirectDuration 320 | */ 321 | public function setRedirectDuration($redirectDuration) { 322 | $this->redirectDuration = $redirectDuration; 323 | } 324 | 325 | /** 326 | * @return int 327 | */ 328 | public function getConnectDuration() { 329 | return $this->connectDuration; 330 | } 331 | 332 | /** 333 | * @param int $connectDuration 334 | */ 335 | public function setConnectDuration($connectDuration) { 336 | $this->connectDuration = $connectDuration; 337 | } 338 | 339 | /** 340 | * @return int 341 | */ 342 | public function getBackendDuration() { 343 | return $this->backendDuration; 344 | } 345 | 346 | /** 347 | * @param int $backendDuration 348 | */ 349 | public function setBackendDuration($backendDuration) { 350 | $this->backendDuration = $backendDuration; 351 | } 352 | 353 | /** 354 | * @return int 355 | */ 356 | public function getFirstPaintTime() { 357 | return $this->firstPaintTime; 358 | } 359 | 360 | /** 361 | * @param int $firstPaintTime 362 | */ 363 | public function setFirstPaintTime($firstPaintTime) { 364 | $this->firstPaintTime = $firstPaintTime; 365 | } 366 | 367 | /** 368 | * @return int 369 | */ 370 | public function getFirstContentfulPaintTime() { 371 | return $this->firstContentfulPaintTime; 372 | } 373 | 374 | /** 375 | * @param int $firstPaintTime 376 | */ 377 | public function setFirstContentfulPaintTime($firstContentfulPaintTime) { 378 | $this->firstContentfulPaintTime = $firstContentfulPaintTime; 379 | } 380 | 381 | /** 382 | * @return int 383 | */ 384 | public function getDomInteractiveTime() { 385 | return $this->domInteractiveTime; 386 | } 387 | 388 | /** 389 | * @param int $domInteractiveTime 390 | */ 391 | public function setDomInteractiveTime($domInteractiveTime) { 392 | $this->domInteractiveTime = $domInteractiveTime; 393 | } 394 | 395 | /** 396 | * @return int 397 | */ 398 | public function getDomContentLoadedTime() { 399 | return $this->domContentLoadedTime; 400 | } 401 | 402 | /** 403 | * @param int $domContentLoadedTime 404 | */ 405 | public function setDomContentLoadedTime($domContentLoadedTime) { 406 | $this->domContentLoadedTime = $domContentLoadedTime; 407 | } 408 | 409 | /** 410 | * @return int 411 | */ 412 | public function getDomContentLoadedDuration() { 413 | return $this->domContentLoadedDuration; 414 | } 415 | 416 | /** 417 | * @param int $domContentLoadedDuration 418 | */ 419 | public function setDomContentLoadedDuration($domContentLoadedDuration) { 420 | $this->domContentLoadedDuration = $domContentLoadedDuration; 421 | } 422 | 423 | /** 424 | * @return int 425 | */ 426 | public function getOnloadTime() { 427 | return $this->onloadTime; 428 | } 429 | 430 | /** 431 | * @param int $onloadTime 432 | */ 433 | public function setOnloadTime($onloadTime) { 434 | $this->onloadTime = $onloadTime; 435 | } 436 | 437 | /** 438 | * @return int 439 | */ 440 | public function getOnloadDuration() { 441 | return $this->onloadDuration; 442 | } 443 | 444 | /** 445 | * @param int $onloadDuration 446 | */ 447 | public function setOnloadDuration($onloadDuration) { 448 | $this->onloadDuration = $onloadDuration; 449 | } 450 | 451 | /** 452 | * @return int 453 | */ 454 | public function getFullyLoadedTime() { 455 | return $this->fullyLoadedTime; 456 | } 457 | 458 | /** 459 | * @param int $fullyLoadedTime 460 | */ 461 | public function setFullyLoadedTime($fullyLoadedTime) { 462 | $this->fullyLoadedTime = $fullyLoadedTime; 463 | } 464 | 465 | /** 466 | * @return int 467 | */ 468 | public function getRumSpeedIndex() { 469 | return $this->rumSpeedIndex; 470 | } 471 | 472 | /** 473 | * @param int $rumSpeedIndex 474 | */ 475 | public function setRumSpeedIndex($rumSpeedIndex) { 476 | $this->rumSpeedIndex = $rumSpeedIndex; 477 | } 478 | 479 | /** 480 | * @return array 481 | */ 482 | public function getResources() { 483 | return $this->resources; 484 | } 485 | 486 | /** 487 | * @param array $resources 488 | */ 489 | public function setResources($resources) { 490 | $this->resources = $resources; 491 | } 492 | 493 | /** 494 | * @return string 495 | */ 496 | public function __toString() { 497 | return $this->getId(); 498 | } 499 | } 500 | -------------------------------------------------------------------------------- /tests/AbstractGTMetrixTest.php: -------------------------------------------------------------------------------- 1 | client = new GTMetrixClient(); 23 | $this->client->setUsername(getenv('GTMETRIX_USERNAME')); 24 | $this->client->setAPIKey(getenv('GTMETRIX_APIKEY')); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/GTMetrixFunctionalTest.php: -------------------------------------------------------------------------------- 1 | client->getBrowsers(); 13 | foreach ($browsers as $browser) { 14 | $this->assertInstanceOf('LightningStudio\GTMetrixClient\GTMetrixBrowser', $browser); 15 | } 16 | } 17 | 18 | public function testGetLocations() { 19 | $locations = $this->client->getLocations(); 20 | foreach ($locations as $location) { 21 | $this->assertInstanceOf('LightningStudio\GTMetrixClient\GTMetrixLocation', $location); 22 | } 23 | } 24 | 25 | public function testStart() { 26 | $test = $this->client->startTest('https://www.wikipedia.org/'); 27 | $this->assertNotEmpty($test->getId()); 28 | while ($test->getState() != GTMetrixTest::STATE_COMPLETED && 29 | $test->getState() != GTMetrixTest::STATE_ERROR) { 30 | $this->client->getTestStatus($test); 31 | sleep(5); 32 | } 33 | } 34 | } 35 | --------------------------------------------------------------------------------