simple dom php 404 error

0

I have the following code:

<?php

include './simple_html_dom.php';

//Este link existe
$teste = new simple_html_dom("http://www.btolinux.com.br/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
    $teste->find("html");
}

//Aqui estou forçando um erro 404.
$teste = new simple_html_dom("http://www.btolinux.com.br/error/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
    $teste->find("html");
}

//A partir de agora todo objeto que eu criar vai estar com erro
$teste = new simple_html_dom("http://www.btolinux.com.br/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
    $teste->find("html");
}

?>

I've tried several ways I've already used unset ($ test) and nothing happens, I already tried to rewrite it using:

$teste = new simple_html_dom();
$teste->load_file("http://www.btolinux.com.br/");

OR

$teste = file_get_html("http://www.btolinux.com.br/");

And it only gets worse ...

I basically believe it to be an object persistence error in memory, since the error that appears in the 3rd object is:

  

Fatal error: Call to a member function find () on a non-object in /var/www/html/crawler/simple_html_dom.php on line 1113

Well, I've tried everything, but I can not find an answer ...

for anyone trying to download the class simple_html_dom

    
asked by anonymous 19.05.2014 / 00:15

2 answers

2

Pdonatilio solved the problem by not using the class when there is no file, but that solves part of the problem. The central issue is that the class generates a fatal error and will no longer run to create new instances, so the new objects will all be in error. Not that the solution is wrong, but I think this should be investigated.

For me it's a class bug, because a class should escape from simple errors like file not found. In this case, you should look at Simple-dom-parser bug list if there is no bug report and report, if there is not. The error can also be in the attempt to escape, problem of php version, etc., have to talk like the people who developed, otherwise you give a curve in this specific problem, but it goes back for another reason.

    
19.05.2014 / 05:36
0

I solved the problem by making the following change:

Replace this:

$teste = new simple_html_dom("http://www.btolinux.com.br/error/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
   $teste->find("html");
}

For this reason

$html = @file_get_contents("http://www.btolinux.com.br/error/");
if ($html!='') {
   $teste = new simple_html_dom($html);
   echo 'SIZE: '.$teste->original_size."<br>";
   $teste->find("html")
}

And it worked ... Well, good evening guys ... and see you around ...

    
19.05.2014 / 03:08