1

I'm parsing some news from one of the Turkish Health Ministry's websites. But for instance if website is down now or can't be loaded, my website doesn't load the content after the part that i parse the news. Is there a way to reduce the parsing time ( because of the problem, my website gets loaded in 1 minute nearly ) and if it returns null, just write something like, can't make connection or something like that error message ?

<?php
$html = file_get_html('http://www.tkhk.gov.tr/TR,6/duyurular.html');
$i = 0;
foreach($html->find('a.belge_alt_b') as $element2){
echo "<div class=\"post\">
<div class=\"matter\">
<h3><a target=\"_blank\" href=\"http://www.tkhk.gov.tr".$element2->href." \">". $element2->plaintext . "</a></h3> 
</div>
</div>
";
$i++ ;
if($i > 4) break;
}
?>
  • think like you need the stock exchange values. won't you parse them ? this is just like that. –  Jun 12 '13 at 00:51
  • Why not just load a place holder like "Loading content" and use `ajax` to load the specific content? – R. S. Jun 12 '13 at 04:43

1 Answers1

0

You can use the PHP curl library instead of file_get_html() and set the timeout appropriately. Setting Curl's Timeout in PHP

Community
  • 1
  • 1
danielrsmith
  • 4,050
  • 3
  • 26
  • 32
  • If the OP wants to stick with `file_get_html()`, then he could use curl to check the status code first: http://stackoverflow.com/questions/2539926/validate-links-with-php/2539983#2539983 – jk. Jun 12 '13 at 00:49
  • 1
    @jk. - that is fine, except then he'd be making two requests, when he could just make one. – danielrsmith Jun 12 '13 at 00:52
  • Agreed, just thought I throw that out there. – jk. Jun 12 '13 at 00:53