1

I want to create site map for my site. So before creating sitemap, i want to know the status code of each url. I have used curl option to deduct status code. I have more than 400 urls in my site. if i use curl, its taking long time.

Only i want to allow the url which is contain status code 200.

Could you please any one tell me any other option to deduct each url's status code.

I have used below curl code.

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlparam);  
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 240);  

curl_exec($ch);
$curlcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $curlcode;

reference link

Community
  • 1
  • 1
Kalidasan
  • 277
  • 3
  • 16

1 Answers1

1

I ran into this same issue a few months ago. I found that using this code example to access my own page status codes was much faster:

<?php
//
// Checking the status of a web page - funmin.com
//

$server="www.YOUR_WEBSITE.com";
function sockAccess($page)
{
   $errno = "";
   $errstr = "";
   $fp = 0;
   global $server;
   $fp = fsockopen($server, 80, $errno, $errstr, 30);

   if ($fp===0)
   {
      die("Error $errstr ($errno)");
   }
   $out = "GET /$page HTTP/1.1\r\n";
   $out .= "Host: $server\r\n";
   $out .= "Connection: Close\r\n\r\n";

   fwrite($fp,$out);
   $content = fgets($fp);
   $code = trim(substr($content,9,4));
   fclose($fp);
   return intval($code);
}
?>

Further documentation may be found here: http://www.forums.hscripts.com/viewtopic.php?f=11&t=4217

Daniel Li
  • 14,976
  • 6
  • 43
  • 60
  • Thanks Hope :) But its also taking long time. ie, for more than 400 url's, its taking more than 4 mins. – Kalidasan Jul 07 '12 at 08:39
  • How about using `$out = "HEAD /$page HTTP/1.1\r\n";`? Do you also take into account how slow/fast are the websites you are trying to query? – Arvin Jul 07 '12 at 11:30