38650

Website becomes unusable while downloading file served by PHP script

Question:

I'm running IIS 8.0 and have a script that serves various downloads when someone clicks on a download link. However I'm running into an issue where as long as a user is downloading something the website is completely unresponsive until that download completes. Below is the code for the download script. This script is being opened in a new window.

$extension = fileexten($filename); if(($filename!= false)&&($fakename!=false&& @fopen($filename,'r')==true)){ $mime = contenttype($extension); set_time_limit(0); header('Pragma: public'); header('Expires: 0'); header("Content-Type:".$mime); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Disposition: attachment;filename='.$fakename.'.'.$extension); header("Content-Transfer-Encoding: binary"); if (ob_get_length() > 0) { ob_end_clean(); } flush(); readfile($filename); } else{ $error = "<h3>We could not find this file</h3>";} // If the filename or fake filename could not be retrieved. }

Answer1:

Close the session before outputting the file.

session_write_close(); readfile($filename);

The session can only be opened by one PHP process at a time, and any other requests that issue a session_start() command will block while waiting for access to the session data file.

Recommend

  • Symfony2-entityManager inside an Entity
  • Fancybox - Opening a link inside a fancybox into the same fancybox?
  • Delete all Cookies of browser using javascript
  • load an ad (div) just once on first load
  • OAuth 2.0 - When should an access token be renewed with refresh token?
  • How does a browser handle cookie with no path and no domain
  • Javascript delete cookie before reload or redirect
  • Nginx raises 404 when using format => 'js'
  • How can I stop .htaccess redirecting a subdomain to the main site?
  • How to Cache Images Dynamically-Generated with PHP?
  • Pass pointer array to function
  • get src attribute of an image based on class or id
  • VB.NET 2012 Property Set on Property Get
  • Serve file to user over http via php
  • How to know which Linq statement produced the SQL on hand during runtime?
  • Easiest way to get current unix timestamp via XSL
  • How to get current document uri in XSLT?
  • Security issues with PHP's Readfile method
  • how to upload multiple files in c# windows application
  • Alert pop up with LWUIT
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Handling un-mapped Rest path
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to make Safari send if-modified-since header?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Circular dependency while pushing http interceptor
  • Linker errors when using intrinsic function via function pointer
  • AngularJs get employee from factory
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory
  • costura.fody for a dll that references another dll
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?