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 6254099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:07:45+00:00 2026-05-24T14:07:45+00:00

I would like to grab other websites information, so, I have a function like

  • 0

I would like to grab other websites information, so, I have a function like this:

$doc = new DOMDocument();
@$doc->loadHTMLFile($aUrl);
$xpath = new DOMXPath($doc);  

And it will help me to get the url from the client, but I am worry that some sites may make my program crash, for example, they are timeout, or no response, or keep redirecting or return me a very big web site that may make my program no memory. How can I avoid this?

  • 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-05-24T14:07:45+00:00Added an answer on May 24, 2026 at 2:07 pm

    I would use cURL to fetch the contents of the website, since that allows for far more configuration, and you can set a couple of the options to address your concerns. This should do what you need:

    <?php
    
    $aUrl = "http://www.example.com";
    $ch = curl_init($aUrl);
    
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    
    $html = curl_exec($ch);
    curl_close($ch);
    
    $maxlength = 51200; // 50 kilobytes
    if ($html && strlen($html) < $maxlength) {
        $doc = new DOMDocument();
        @$doc->loadHTML($html);
        $xpath = new DOMXPath($doc);
    
        // Do your processing here.
    } else {
        die('There was an error fetching the HTML.');
    }
    
    ?>
    

    That takes care of timeouts and limits redirection to two. It also does not attempt to process pages larger than 50 kilobytes (you may want to adjust that based on how large you expect the page to be).

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

Sidebar

Related Questions

I would like to have a submit button on other people's HTML pages (with
I would like to have a reference for the pros and cons of using
I would like to allow my users to see other users data. I am
First I would like to say that I have only worked with java for
I have two arrays of x - y coordinates, and I would like to
I would like to be able to have a series of nested loops that
I know this is a really rookie question but would like some understanding off
I have multiple TextViews . When I click on the TextView I would like
I would like to get the title of a base function (e.g.: rnorm )
I would like to display the body contents of an email. I have tried

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.