Jump to content

PHP page speed checker


oracle765

Recommended Posts

http://www.localsuburb.com/mobile-page-speed-check.php
<?php
include_once('simple_html_dom.php');
$target_url = "http://www.expresslawnmowing.com.au/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('a') as $link)
{
//echo $link->href."<br />";
$http = 'http';
$https = 'https';

switch (true){
   case strpos($link,$http) !== false:
   case strpos($link,$https) !== false:   
   case strpos($link,$target_url) !== false:
   $mobile_check = 'https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key=AIzaSyDkEX-f1JNLQLC164SZaobALqFv4PHV-kA&screenshot=true&snapshots=true&locale=en_US&url=' .$link->href. '%2F&strategy=mobile&filter_third_party_resources=false&callback=_callbacks_._Ce2bYp0wchLY';

echo $mobile_check. "<br /><br /><br />";
echo $link. "<br /><br /><br />";
break;

}
}
?>

Hi Professionals

 

I am trying to write a page speed checker that will get a list of URLs to send to google page speed so I can check more than 1 page.  I have two problems which are as follows

 

Q1: I am trying to eliminate any other URLs it finds EG if I check for expresslawnmowing.com.au it finds links to our other webpages such as expresspestcontrol.com.au.  I do not want it to do this I only want to find the URL in question and all of its sub-urls

 

Q2:  Once I get the list of urls which is just currently opening in an editor, s there a way to loop through these to send them to the browser for checking

 

please find my code, you can also find this on my test domain also attached

 

Link to comment
Share on other sites

The reason you see your domain is because the relative urls are scraping need to be fixed

 

from target link

#carousel-example-generic
#carousel-example-generic

 

one directory up
../contact/
../our-services/
../all-other-services/

 

two direcories up
/../../our-services/
/../../our-services/
/../../our-services/

 

I did a cheap fix for you, when it comes down to handling targeted directories you'll have to pop / positions accordingly

<?php
include_once('simple_html_dom.php');
$target_url    = "http://www.expresslawnmowing.com.au/";
$target_domain = parse_url(trim($target_url), PHP_URL_HOST);
$target_domain = str_replace("www.", "", $target_domain);
$hrefs         = array();
$html          = new simple_html_dom();
$html->load_file($target_url);
foreach ($html->find('a') as $link) {
    $url = trim($link->href);
    if (!preg_match("~:\/\/~", $url)) {
        if (substr($url, 0, 1) == "/") {
            $url = ltrim($url, "/");
        }
        $url = str_replace(array(
            "../",
            "./"
        ), "", $url);
        $url = "http://" . $target_domain . "/" . $url;
    }
    $hrefs[] = $url;
   
}
if (!empty($hrefs)) {
    $hrefs = array_unique($hrefs);
    foreach ($hrefs as $href) {
        $mobile_check = 'https://www.googleapis.com/pagespeedonline/v3beta1/mobileReady?key=AIzaSyDkEX-f1JNLQLC164SZaobALqFv4PHV-kA&screenshot=true&snapshots=true&locale=en_US&url=' . $href . '%2F&strategy=mobile&filter_third_party_resources=false&callback=_callbacks_._Ce2bYp0wchLY';
       
        echo $mobile_check . "<br /><br /><br />";
        echo $href . "<br /><br /><br />";
    }
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.