/example/get-google-pagespeed-analysis.php

https://github.com/nuhuxi/SEOstats · PHP · 39 lines · 10 code · 4 blank · 25 comment · 0 complexity · 1d0a1b2c87007000539a631f6cd78844 MD5 · raw file

  1. <?php
  2. /**
  3. * SEOstats Example - Get Google Pagespeed Analysis
  4. *
  5. * @package SEOstats
  6. * @author Stephan Schmitz <eyecatchup@gmail.com>
  7. * @copyright Copyright (c) 2010 - present Stephan Schmitz
  8. * @license http://eyecatchup.mit-license.org/ MIT License
  9. * @updated 2013/12/17
  10. */
  11. // NOTE: The given path to the autoload.php assumes that you installed SEOstats via composer
  12. // and copied this example file from ./vendor/seostats/seostats/example/example.php to ./example.php
  13. //
  14. // If you did NOT installed SEOstats via composer but instead downloaded the zip file from github.com,
  15. // you need to follow this steps:
  16. //
  17. // 1. Comment-in line 24 (remove hash char "#") and comment-out line 25 (prepend hash char "#")
  18. // 2. Copy this example file (and the others) from ./example/example.php to ./example.php
  19. //
  20. // For further reference see: https://github.com/eyecatchup/SEOstats/issues/49
  21. // Bootstrap the library / register autoloader
  22. #require_once realpath(__DIR__ . '/SEOstats/bootstrap.php');
  23. require_once realpath(__DIR__ . '/vendor/autoload.php');
  24. try {
  25. $url = 'http://www.nahklick.de/';
  26. /**
  27. * Get the Google Pagespeed Analysis metrics for the given URL.
  28. * NOTE: Requires an API key to be set in SEOstats/Config/ApiKeys.php
  29. */
  30. $pagespeed = \SEOstats\Services\Google::getPagespeedAnalysis($url);
  31. print_r($pagespeed);
  32. }
  33. catch (\Exception $e) {
  34. echo 'Caught SEOstatsException: ' . $e->getMessage();
  35. }