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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:55:12+00:00 2026-05-26T20:55:12+00:00

I have to fetch multiple web pages, let’s say 100 to 500. Right now

  • 0

I have to fetch multiple web pages, let’s say 100 to 500. Right now I am using curl to do so.

function get_html_page($url) {
    //create curl resource
    $ch = curl_init();

    //set url
    curl_setopt($ch, CURLOPT_URL, $url);

    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);

    //$output contains the output string
    $html = curl_exec($ch);

    //close curl resource to free up system resources
    curl_close($ch);

    return $html;
 }

My major concern is the total time taken by my script to fetch all these web pages. I know that the time taken is directly proportional to my internet speed and hence the majority time is taken by $html = curl_exec($ch); function call.

I was thinking that instead of creating and destroying curl instance again and again for each and every web page, if I create it only once and then just reuse it for each and every page and finally in the end destroy it. Something like:

<?php

function get_html_page($ch, $url) {
    //$output contains the output string
    $html = curl_exec($ch);
    return $html;
 }

   //create curl resource
    $ch = curl_init();

    //set url
    curl_setopt($ch, CURLOPT_URL, $url);

    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    .
    .
    .

    <fetch web pages using get_html_page()>    

    .
    .
    .
    //close curl resource to free up system resources
    curl_close($ch);
?>

Will it make any significant difference in the total time taken? If there is any other better approach then please let me know about it also?

  • 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-26T20:55:13+00:00Added an answer on May 26, 2026 at 8:55 pm

    How about trying to benchmark it? It may be more efficient to do it the second way, but I don’t think it will add up to much. I’m sure your system can create and destroy curl instances in microseconds. It has to initiate the same HTTP connections each time either way, too.

    If you were running many of these at the same time and were worried about system resources, not time, it might be worth exploring. As you noted, most of the time spent doing this will be waiting for network transfers, so I don’t think you’ll notice a change in overall time with either method.

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

Sidebar

Related Questions

I have to scrap a web site where i need to fetch multiple URLs
Using Java,I have to fetch multiple sets of values from an XML file to
I have a paginated collection that could be simultaneously making multiple fetch()es. E.G. a
I have to fetch all the files from a folder and i am using
I am using graph API. I have to fetch feed(i.e.. posts on the particular
Using SQL Server 10.0 and 10.5 I'm trying to fetch multiple rows into one
So, here is my little problem. Let's say I have a list of buckets
I am using Spring Web MVC for my application. I have 1 dropdown list
I have written a MySQL query (Ad rotate algorithm) to fetch records from multiple
I'm designing a web based php reporting system. It involves multiple pages that insert

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.