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

  • Home
  • SEARCH
  • 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 633989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:14:44+00:00 2026-05-13T20:14:44+00:00

My web host has a process killer which terminates any process running longer than

  • 0

My web host has a “process killer” which terminates any process running longer than about 5 minutes, so my download script can’t run for that long.

I thought I’d use fread-print for a few seconds, just to catch if the user aborts the download initially and then use fpassthru to to dump the rest of the file.

ob_end_clean();
$file = fopen($this->m_path,'rb'); // read binary
fseek($file, $startByte);
$cnt = 0;
while (!feof($file) && (!connection_aborted()) && ($bytesSent<$bytesToSend) )
{
    $cnt++;
    if($cnt > 25) // to simulate breaking the loop after a certain time has passed
        break;
    set_time_limit(0);
    $buffer = fread($file, 32*1024);
    print($buffer);
    //flush();
    $bytesSent += strlen($buffer);
}
flush(); // has no effect on fpassthru

// --- insert point for the code below --

if(!feof($file))
{
    fpassthru($file);
}
fclose($file);

The problem is that fpassthru keeps the script running during the whole download. I’ve tired using output buffering, which results in the script exiting quickly, but the download gets cut off after about 8 minutes (I’m sending a 30 MB file at 15 kB/s).

One thing that makes the script exit quickly and lets the download complete is if I insert the following at the “insert point” above:

echo("X"); // or pretty much any string literal
flush();

It works every time, but the file gets corrupted of course (as expected).

If I insert something like this instead:

echo fread($file, 16);
flush();

it doesn’t work (fpassthru doesn’t allow the script to exit).

It feels like I’ve tried everything. I tired closing and reopening the file, sleeping, calling flush multiple times. It makes little to no sense to me why it would suddenly work when I print a string literal.

PHP version 5.2.11
Apache 2.2.9

EDIT:

I ended up getting my web host to extend the timeout period to 40 minutes so that I can serve the files with fread-echo and exit cleanly with time to spare. I serve relatively small files, and resuming is supported for the few visitors who get their transfers cut off.

I also made (and rejected) a redirect based solution where I set the headers I wanted in .htaccess, but that solution would force me to disallow partial downloads for most, since I had problem counting the used bandwidth.

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

    I see two immediate solutions to your problem:

    1. Get another host that doesn’t do that sort of stuff
    2. Instead of letting the script manage the download, let apache do it, just redirect to the actual file after updating your counters and such. header('Location: '.$actualFile, true, 303) (the 303 signifies “See Other Resource”, to prevent post data from posting again to the next url) After that you can just exit;
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 386k
  • Answers 386k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The way they lay out the rows in that tutorial… May 14, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer If you are familiar with Blend behaviors, triggers, and actions… May 14, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer The original cookie specification of Netscape (see this cached version)… May 14, 2026 at 11:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.