#11 find(); got Fatal Errors


I got the fatal error when doing a find(). It seems that if the find() function fails to find what I'm looking for, it throws a fatal error which stops the script from running. Huge pain… Is there a way to further check the $html for let’s say a certain table exists before calling the find() function?

Please help.


  • nickl-

    You are not giving us much to go on here but if I would guess I suppose you could try

    if (!false === strpos($html->save(), 'certain table')) {
    // certain table does exist

    If you explained the error maybe we could fix that, all I can do for you now. Hope it helps, let us know.

  • Libby

    I'm getting fatal errors in find() as well, but they happen only after a "failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found" PHP Warning at file_get_contents. I tried wrapping the return of file_get_html in a urlExists function

    function url_exists($url){
    if ((strpos($url, "http")) === false) $url = "http://" . $url;
    if (is_array(@get_headers($url)))
    return true;
    return false;

    if (url_exists($url)) {
    if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
    return false;
    // The second parameter can force the selectors to all be lowercase.
    $dom->load($contents, $lowercase, $stripRN);
    return $dom;

    but the 404 Warning is still raised and find() still fatally dies. Is there another way to exit the file_get_html function if the URL passed returns a 404? Then it would never get to find(). EIther way, find() should recover rather than die.

  • John Schlick
    John Schlick

    to anonymous who created the ticket:

    1: Please make sure that you are running the newest version of simple_html_dom then
    2: Please share the text of the errors you are getting - especially the line number.
    3: If possible, can you generate a sample_html file that is as simple as possible that recreates the issue and attach it to the ticket so that we can have something to recreate the issue with?

    To Libby who wrote a followup:

    After a failed to retrieve error, I would expect you to get a false back from file_get_html, and $dom->find is not a valid method of false. you can use is_object to detect this. However, it appears since you say you are getting an error IN find (and not on the call TO find) that there may be an error in find and you do not have a false instead of an object. In that case, please see the comments above made to anonymous.

    I will leave this support request open for the next three months to see if there is actionable feedback, and if none appears I will assume that you have solved the issue, and close the ticket.

  • John Schlick
    John Schlick

    • status: open --> pending
    • milestone: --> v1.0_(example)
  • Ken Irwin
    Ken Irwin

    I think that what Libby is describing here is in line with what I experienced and asked about in another entry: https://sourceforge.net/p/simplehtmldom/support-requests/17/

    John said that a failed file_get_html should return FALSE, but instead, I'm getting a situation where the script dies.

    Here's the error; I just found this and will add it to my ticket as well:
    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 16 bytes) in /var/www/docs/lib/ken/c4l/domfail/simple_html_dom.php on line 1551