Improve This 404 Checker PHP Script? -


it's main purpose check urls. have create 404.txt , sites.txt, put urls want in sites.txt , run script below called grab.php, urls 404 in sites.txt go in 404.txt. remember has in same folder, 404.txt,sites.txt , grab.php.

you see php script doesn't work time, cannot handle thousands of urls. works hundreds or less, improve this?

 <?php error_reporting(0); $error_404 = "not found"; $list_404 = array(); $sites = file('sites.txt', file_ignore_new_lines | file_skip_empty_lines);  foreach($sites $site) {         $response = get_headers($site);         if (strpos($response[0], $error_404))         {                 $list_404[]=$site." ";         } }  file_put_contents('404.txt',$list_404); ?> 

you try see going wrong:

<?php  // display errors ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1);  // open file $sitefile = fopen("sites.txt", "r"); // create array store 404 error sites $errorlist = array();  // reading file line line while(!feof($sitefile)){     // site     $site = (string)trim(fgets($sitefile));     // headers     $headers = get_headers($site);     // parse status code header     $status = substr($headers[0], 9, 3);     // if status code 404, push array     if(intval($status) == 404){         array_push($errorlist, $site);         echo "<li><b>{$site} {$headers[0]}</b></li>";     }     // output status code (just can see it)     else {         echo "<li>{$site} {$headers[0]}</li>";     } }  // file writing here  // close sites file fclose($sitefile); 

at least way you'll able see errors status sites in list. also, sure of urls in sites file formatted http

sites.txt:

http://www.google.com http://www.facebook.com http://www.gmail.com http://hotdot.pro/en/404/ 

html output:

http/1.0 200 ok http/1.1 302 found http/1.0 301 moved permanently http/1.1 404 not found 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -