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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:14:43+00:00 2026-06-08T23:14:43+00:00

i have a downloading website written in php to download from remote servers using

  • 0

i have a downloading website written in php to download from remote servers using curl but the thing is the httpd connections are not terminated they are still in sleeping mod which is killing my server resources, here is the top output

top - 20:55:36 up 4 days, 13:41, 1 user, load average: 1.99, 5.73,  
10.47 Tasks: 2207 total, 5 running, 2202 sleeping, 0 stopped, 0 zombie Cpu(s): 24.1%us, 1.5%sy, 0.0%ni, 73.3%id, 0.0%wa, 0.0%hi, 1.1%si,  
0.0%st Mem: 4045976k total, 4000712k used, 45264k free, 1448k buffers Swap: 8385920k total, 2353584k used, 6032336k free, 30336k cached

i traced one pid using this strace -p 22254 -s 80 -o /tmp/debug.lighttpd.txt i got this output which i’m not sure but it seems to be polling and polling

clock_gettime(CLOCK_MONOTONIC, {10396, 471413333}) = 0
poll([{fd=24, events=POLLOUT}], 1, 725) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {10397, 196905333}) = 0
clock_gettime(CLOCK_MONOTONIC, {10397, 196955333}) = 0
poll([{fd=24, events=POLLOUT}], 1, 1000) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {10398, 197890333}) = 0
clock_gettime(CLOCK_MONOTONIC, {10398, 197937333}) = 0
poll([{fd=24, events=POLLOUT}], 1, 1000) = 0 (Timeout)

are there any http headers that i’m missing or is there anyway to terminate those connections, any ideas??

here is the php code that i’m using, this is the important part of it

header('Content-Disposition: filename='.$fileName);
header("Content-Type: application/octet-stream\n"); 
header("Connection: close\n");
header("Accept-Ranges: bytes");
header("Content-Range: bytes 0-$size2/$size"); 
header("Content-Length: ".$size);

while($start_range <= $end_range) { 
if (connection_status()!=0) return(false); 
if(($start_range + 999999) > $end_range) $range = $start_range.'-'; 
else $range = $start_range.'-'.($start_range + 999999); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $fileLocation); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($cookie != false) curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); 
if ($refurl != false) curl_setopt($ch, CURLOPT_REFERER, $refurl); 
curl_setopt($ch, CURLOPT_RANGE,$range); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1'); 
curl_exec($ch); 
curl_close($ch);
$start_range +=1000000; 

flush(); 
ob_flush();
ob_end_flush();
}
  • 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-08T23:14:46+00:00Added an answer on June 8, 2026 at 11:14 pm

    So the problem was with http headers keep-alive, the connection was kept alive causing the trouble, here is how i fixed it.

    i didn’t initiate and close curl every time, instead one curl is initialed and i send http headers defining keep-alive and keep-alive time. this solved my problem

    $ch = curl_init(); 
    while($start_range <= $end_range) { 
        if (connection_status()!=0) return(false); 
        if(($start_range + 999999) > $end_range) $range = $start_range.'-'; 
        else $range = $start_range.'-'.($start_range + 999999); 
        curl_setopt($ch, CURLOPT_URL, $fileLocation); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Connection: Keep-Alive',
        'Keep-Alive: 300',
        'Cache-Control: no-cache'
        ));
        if ($cookie != false) curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); 
        if ($refurl != false) curl_setopt($ch, CURLOPT_REFERER, $refurl); 
        curl_setopt($ch, CURLOPT_RANGE,$range); 
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1'); 
        $content = curl_exec($ch); 
        echo $content;
        unset($content);
        $start_range +=1000000;     
        flush(); 
        ob_flush();
    }
    curl_close($ch);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am downloading a file from a website and I have the link. But
I want to download some files from my website and have to upload the
I am using libcurl I have my downloading of files inside of a class,
I have a service that is downloading a file. When the download is done,
I have an app with in-app downloading. I successfully download mp3 files in this
I have c# code behind my Excel-dna addin which is successfully downloading data from
i am trying to implement pretty url. Everything i have written in PHP and
I have written a script that will keep itself up to date by downloading
I have this code I have written to make my life easier when downloading
I would like to retrieve the original file name from a website while downloading

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.