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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:48:50+00:00 2026-05-30T14:48:50+00:00

I’m trying to find a way to only quickly access a file and then

  • 0

I’m trying to find a way to only quickly access a file and then disconnect immediately.

So I’ve decided to use cURL since it’s the fastest option for me. But I can’t figure out how I should “disconnect” cURL.

With the code below, Apache’s access logs says that the file I tried accessing was indeed accessed, but I’m feeling a little iffy about this, because when I just run the while loop without breaking out of it, it just keeps looping. Shouldn’t the loop stop when cURL has finished fetching the file? Or am I just being silly; is the loop just restarting constantly?

<?php
$Resource = curl_init();
curl_setopt($Resource, CURLOPT_URL, '...');
curl_setopt($Resource, CURLOPT_HEADER, 0);
curl_setopt($Resource, CURLOPT_USERAGENT, '...');
while(curl_exec($Resource)){
    break;
}
curl_close($Resource);
?>

I tried setting the CURLOPT_CONNECTTIMEOUT_MS / CURLOPT_CONNECTTIMEOUT options to very small values, but it didn’t help in this case.

Is there a more “proper” way of doing 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-30T14:48:51+00:00Added an answer on May 30, 2026 at 2:48 pm

    This statement is superflous:

    while(curl_exec($Resource)){
        break;
    }
    

    Instead just keep the return value for future reference:

    $result = curl_exec($Resource);
    

    The while loop does not help anything. So now to your question: You can tell curl that it should only take some bytes from the body and then quit. That can be achieved by reducing the CURLOPT_BUFFERSIZE to a small value and by using a callback function to tell curl it should stop:

    $withCallback = array(
        CURLOPT_BUFFERSIZE       => 20,  # ~ value of bytes you'd like to get
        CURLOPT_WRITEFUNCTION    => function($handle, $data) {
            echo "WRITE: (", strlen($data), ") $data\n";
            return 0;
        },
    );
    
    $handle = curl_init("http://stackoverflow.com/");
    curl_setopt_array($handle, $withCallback);
    curl_exec($handle);
    curl_close($handle);
    

    Output:

    WRITE: (10) <!DOCTYPE
    

    Another alternative is to make a HEAD request by using CURLOPT_NOBODY which will never fetch the body. But it’s not a GET request.

    The connect timeout settings are about how long it will take until the connect times out. The connect is the phase until the server accepts input from curl and curl starts to know about that the server does. It’s not related to the phase when curl fetches data from the server, that’s

    CURLOPT_TIMEOUT The maximum number of seconds to allow cURL functions to execute.

    You find a long list of available options in the PHP Manual: curl_setopt­Docs.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters

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.