Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:40:54+00:00 2026-06-12T00:40:54+00:00

The following function receives a string parameter representing an url and then loads the

  • 0

The following function receives a string parameter representing an url and then loads the url in a simple_html_dom object. If the loading fails, it attemps to load the url again.

  public function getSimpleHtmlDomLoaded($url)
  {
    $ret = false;
    $count = 1;
    $max_attemps = 10;
    while ($ret === false) {
      $html = new simple_html_dom();
      $ret = $html->load_file($url);
      if ($ret === false) {
        echo "Error loading url: $url\n";
        sleep(5);
        $count++;
        $html->clear();
        unset($html);
        if ($count > $max_attemps) 
          return false;
      }
    }
    return $html;
  }

However, if the url loading fails one time, it keeps failing for the current url, and after the max attemps are over, it also keeps failing in the next calls to the function with the rest of the urls it has to process.

It would make sense to keep failing if the urls were temporarily offline, but they are not (I’ve checked while the script was running).

Any ideas why this is not working properly?

I would also like to point out, that when starts failing to load the urls, it only gives a warning (instead of multiple ones), with the following message:

PHP Warning: file_get_contents(http://www.foo.com/resource): failed
to open stream: HTTP request failed! in simple_html_dom.php on line
1081

Which is prompted by this line of code:

$ret = $html->load_file($url);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:40:56+00:00Added an answer on June 12, 2026 at 12:40 am

    I have tested your code and it works perfectly for me, every time I call that function it returns valid result from the first time.

    So even if you load the pages from the same domain there can be some protection on the page or server.
    For example page can look for some cookies, or the server can look for your user agent and if it see you as an bot it would not serve correct content.

    I had similar problems while parsing some websites.
    Answer for me was to see what is some page/server expecting and make my code simulate that. Everything, from faking user agent to generating cookies and such.

    By the way have you tried to create a simple php script just to test that ‘simple html dom’ parser can be run on your server with no errors? That is the first thing I would check.

    On the end I must add that in one case, while I failed in numerous tries for parsing one page, and I could not win the masking game. On the end I made an script that loads that page in linux command line text browser lynx and saved the whole page locally and then I parsed that local file which worked perfect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I receive three errors using the following function: Private Sub readWebpage(ByVal url As String)
Given a function which accepts a parameter with the following interface: interface ITest {
I have a javascript function which takes a string as its parameter. This string
I'm trying to create a javascript function that receives a string that is assumed
Have following kernel function: private static String programSource = __kernel void sampleKernel(__global float *Y,
I receive the error below when running the following function. The catch says the
The following function rewrites urls from news and product titles that contain all sorts
The following function is designed to check whether this row in this tables exists.
The following function that reports the current line-number (and time) which I would like
The following function System.Threading.Thread.Sleep(); delay the thread in millisecond, and take the integer value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.