Created
February 10, 2022 08:55
-
-
Save pradeeprjth/3a7c1be5070a5bc3169f85ff2ac2819b to your computer and use it in GitHub Desktop.
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 | |
namespace App\Http\Controllers; | |
class WebPageSizeCheckerController extends Controller | |
{ | |
public function post(Request $request) | |
{ | |
$url = $request->url; | |
$curl = curl_init($url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); | |
$subject = curl_exec($curl); | |
//get the download size of page | |
print("Download size 1: " . curl_getinfo($curl, CURLINFO_SIZE_DOWNLOAD) .'<br>'); | |
preg_match_all('/(?:src=)"([^"]*)"/m', $subject, $matchessrc); | |
preg_match_all('/link.*\s*(?:href=)"([^"]*)"/m', $subject, $matcheslink); | |
$matches = array_merge($matchessrc[1], $matcheslink[1]); | |
$domain = parse_url($url, PHP_URL_SCHEME). '://'.parse_url($url, PHP_URL_HOST); | |
$path = parse_url($url, PHP_URL_PATH); | |
$checked = array(); | |
foreach($matches as $m) | |
{ | |
if($m[0] == '/') | |
$m = $domain.$m; | |
elseif(substr($m, 0, 5) != 'http:' and substr($m, 0, 6) != 'https:') | |
$m = $domain.'/'.$path.'/'.$m; | |
if(in_array($m, $checked)) | |
continue; | |
$checked[] = $m; | |
$curl = curl_init($m); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); | |
$subject = curl_exec($curl); | |
//get the download size of element | |
print("Download size 2: " . curl_getinfo($curl, CURLINFO_SIZE_DOWNLOAD) .'<br>'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment