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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:09:55+00:00 2026-05-17T21:09:55+00:00

About Application I am working on an e-commerce application in PHP. To keep URL’s

  • 0

About Application

I am working on an e-commerce application in PHP. To keep URL’s secure, product download links are kept behind PHP. There is a file, say download.php, which accepts few parameter via GET and verifies them against a database. If all goes well, it serves file using readfile() function in PHP.

About Problem

Now problem comes when file to be passed to readfile() is larger than memory limit set in php.ini
As this application will be used by many users on shared-hosting we cannot relay on altering php.ini settings.

In our effort to find workarounds, I first thought we can go for fread() calls in while loop but it seems that will impose problems as well as highlighted here Downloading large files reliably in PHP

So my best option is to detect/check if server supports X-Accel-Redirect (in case of Nginx) / X-Sendfile (in case of Apache)

If server supports X-Accel-Redirect / X-Sendfile, I can use them and in else block I can make system admin aware about memory limit enforced by php.ini

Ideally, I want to use server side support like X-Accel-Redirect / X-Sendfile wherever possible, and if that doesn’t work – I would like to have a fallback code to read files without readfile().

I am not yet sure as how readfile() and fread() in while loop are different but seems while loop will create problem, again, as suggested in Downloading large files reliably in PHP

Hope to get some help, suggestions, codes, guidance.

Thanks for reading.

  • 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-17T21:09:55+00:00Added an answer on May 17, 2026 at 9:09 pm

    To detect if the mod_xsendfile apache module installed, you can try this code:

    if function_exists('apache_get_modules') 
          && in_array('mod_xsendfile', apache_get_modules()) { 
      header("X-Sendfile"); 
    }
    

    But this code just check if the module installed only, that can cause errors if it’s installed but configured wrongly

    another possible way to do this to setup server-wide variable through Apache’s .htaccess:

    <IfModule mod_xsendfile.c>
      <Files *.php>
        XSendFile On
        XSendFileAllowAbove On
        SetEnv MOD_X_SENDFILE_ENABLED 1
      </Files>
    </IfModule>
    

    and check it form php code:

    if ($_SERVER['MOD_X_SENDFILE_ENABLED']) {
      Header(...)
    }
    

    The common idea is the same for nginx – just pass the value of status variable to backend via HTTP-header or CGI/FastCGI variable.

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

Sidebar

Related Questions

I am working on an application that is about 250,000 lines of code. I'm
I'm working on a PyGTK/glade application that currently has 16 windows/dialogs and is about
I am working on designing and building a desktop application. I am thinking about
I know about Application.Exit() but what if I'm not in a windows forms application
I'm looking for some quick thoughts about a business application I am looking to
I was wondering, how would you go about writing an application that basically houses
My current application has a JFrame with about 15 actions stored as fields within
My application I've recently inherited is FULL of deprecation warnings about the constructor: Date
I was thinking about obfuscating a commercial .Net application. But is it really worth
I'm about to create a web application that requires a lot of different web

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.