Last active
May 11, 2016 00:58
-
-
Save tayfunerbilen/cc1845d4a6433e19e771 to your computer and use it in GitHub Desktop.
Google Sayfa Hız Testi Sınıfı
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Tayfun Erbilen | |
* @web http://www.erbilen.net | |
* @mail [email protected] | |
*/ | |
class googlePageSpeedTest { | |
// hedef site | |
public $target_url; | |
// site ekran görüntüsü | |
public $screenshot = 'true'; | |
// site anlık kareler | |
public $snapshots = 'false'; | |
// dil | |
public $locale = 'tr'; | |
// cihaz (desktop ya da mobile) | |
public $device = 'desktop'; | |
// json çıktısı | |
public $json = false; | |
public function __construct($url) | |
{ | |
$this->target_url = $url; | |
} | |
public function cURL($url) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_REFERER, 'https://www.googleapis.com'); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
return $response; | |
} | |
public function data() | |
{ | |
$url = 'https://www.googleapis.com/pagespeedonline/v3beta1/runPagespeed?screenshot=' . $this->screenshot . '&snapshots=' . $this->snapshots . '&locale=' . $this->locale . '&url=' . rawurlencode($this->target_url) . '&strategy=' . $this->device; | |
$data = $this->cURL($url); | |
if ( $this->json ) | |
return $data; | |
else | |
return json_decode($data, true); | |
} | |
} | |
// örnek kullanımı | |
$speedTest = new googlePageSpeedTest('http://www.erbilen.net'); | |
$speedTest->device = 'mobile'; | |
echo '<pre>'; | |
print_r( $speedTest->data() ); | |
echo '</pre>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment