Zend Platform Download Server In-Depth
- Additional Products:
- Zend Core |
- Zend Studio |
- Zend Guard
Zend Download Server is capable of offloading the process of sending large files from Apache, freeing it to handle the more complicated PHP-based requests. That is, Zend Download Server can cause a 10 times increase in simultaneous file downloads!
There are two modes of operating Zend Download Server - Manual and Transparent. In the Manual mode, you manually invoke the PHP function zend_send_file(), passing it the file name you would like to be downloaded. Calling zend_send_file() immediately starts the file download and terminates your PHP script’s execution.
In the Transparent mode, though, you preconfigure the files to be downloaded using Zend Download Server by mapping these files in the configuration file of your Web server (for instance, add “AddType application/x-httpd-php .mpeg”) and specify the files mime types to be handled in the zend_mime_types.ini file. You can also configure the min_file_size directive (using the Zend Download Server administration UI). As a result, files of the types you have specified where the size is greater than min_file_size, would be automatically handled.
How Zend Download Server Works
Zend Download Server is essentially an independent process that is created when Zend Platform is started (on Apache start). Normally, a request from some Web client is asking to download a file from the Web Server, and the Web Server is handling the request itself. The following diagram illustrates this flow:
Now, suppose that a new request is coming from some Web client asking to download a file using Zend Download Server (either via an explicit call to the API function or using the Transparent mode settings). In return, Apache gets the request, but instead of handling it (something that would consume Apache resources) it uses a pipe (a way of IPC - inter-process communication) and passes the file descriptor of the connection to the Zend Download Server daemon. Zend Download Server, in response, uses ’select’ which is basically a system call used for asynchronous I/O operations. The select system call sleeps until a condition occurs on a file descriptor, a timeout occurs, or a signal is received. In our case, Zend Download Server looks at the return parameter of the select call, finds out which file descriptor has changed, and then uses a socket with an arbitrary port (a port >1024 is picked) to process the request. That way, the file download task is rerouted to another process, which uses a dedicated socket to download the file - without interfering with the Apache process. The following diagram illustrates how this flow looks like:
You can also set the maximal amount of concurrent clients using Zend Download Server as well as setting other settings using the feature's UI. For more information check out the Zend Download Server White Paper.



