1

I'm trying to use file_get_html on a web page to find images (and their URLs) on the page.

<?php
include('simplehtmldom_1_7/simple_html_dom.php');
 $html = file_get_html('https://www.mrporter.com/en-us/mens/givenchy/jaw-neoprene--suede--leather-and-mesh-sneakers/1093998');
foreach($html->find('img') as $e)
        $img_url_array[] = $e->src . '<br>';
      $array_size = sizeof($img_url_array);
       $x =0;
        while($x <$array_size){
       echo "image url is " . $img_url_array[$x] ;
       $x =$x+1;
   }
?>

The script keeps on loading and doesn't pause. Is there a way to set a timeout or an exception?

  • Maybe [set-time-limit](http://php.net/manual/en/function.set-time-limit.php) is what you need – dWinder Dec 30 '18 at 06:41
  • Do you want the time-out on the load of the target HTML (so for `file_get_html()`) only or the whole page? – Nigel Ren Dec 30 '18 at 07:05
  • The target HTML only (file_get_html) – user2533040 Dec 30 '18 at 07:14
  • Not sure if there is that option, you could alternatively fetch the html using curl, https://stackoverflow.com/questions/2582057/setting-curls-timeout-in-php shows hot to set time outs for that. Then load the string or not for timeouts. – Nigel Ren Dec 30 '18 at 07:18
  • Are you from a location that has restrictions accessing to this site? Can you brows this page in your browser without using a VPN or similar services? – Nima Dec 30 '18 at 09:31
  • No, I am able to access the site through my browser. It's just that when I run the code above with that site as the url, file_get_html doesn't load – user2533040 Dec 30 '18 at 10:19

0 Answers0