Alex Rivera | Logout

Running concurrent PHP scripts

Asked 2012-01-17T11:41:45.283
8

I'm having the following problem with my VPS server.

I have a long-running PHP script that sends big files to the browser. It does something like this:

<?php
header("Content-type: application/octet-stream");
readfile("really-big-file.zip");
exit();
?>

This basically reads the file from the server's file system and sends it to the browser. I can't just use direct links(and let Apache serve the file) because there is business logic in the application that needs to be applied.

The problem is that while such download is running, the site doesn't respond to other requests.

Edit
Report

1 Answer

0

I have tried different approaches (reading and sending the files in small chunks [see comments on readfile in PHP doc], using PEARs HTTP_Download) but I always ran into performance problems when the files are getting big.

There is an Apache mod X-Sendfile where you can do your business logic and then delegate the download to Apache. The download will not be publicly available. I think, this is the most elegant solution for the problem.

More Info:

answered 2012-01-17T12:07:11.137

Your Answer