Using PHP to download multi files at one time
<pre><code>class Transfer {

/**
 * @access private
 * @var integer
 */
private $mDownStart;

/**
 * @access private
 * @var integer
 */
private $mFileSize;

/**
 * @access private
 * @var integer
 */
private $mFileHandle;

/**
 * @access private
 * @var string
 */
private $mFilePath;

/**
 * @access private
 * @var string
 */
private $mFileName;

/**
 * @access public
 * @return void
 **/
public function __construct() {
}

/**
 * @access public
 * @return void
 **/
public function Down($pFilePath, $pFileName = '') {
    $this-&gt;mFilePath = $pFilePath;
    if (!$this-&gt;iniFile())
        $this-&gt;sendError();
    $this-&gt;mFileName = empty($pFileName) ? $this-&gt;getFileName() : $pFileName;

    $this-&gt;iniFile();
    $this-&gt;setStart();
    $this-&gt;setHeader();

    $this-&gt;send();

    fclose($this-&gt;mFileHandle);
}

/**
 * @access private
 * @return boolean
 **/
private function iniFile() {
    if (!is_file($this-&gt;mFilePath))
        return false;
    $this-&gt;mFileHandle = fopen($this-&gt;mFilePath, 'rb');
    $this-&gt;mFileSize = filesize($this-&gt;mFilePath);
    return true;
}

/**
 * @access private
 * @return void
 **/
private function setStart() {
    if (isset($_SERVER['HTTP_RANGE'])) {
        preg_match("/^bytes=([0-9]+)-$/i", $_SERVER['HTTP_RANGE'], $match);
        $this-&gt;mDownStart = $match[1];
        fseek($this-&gt;mFileHandle, $this-&gt;mDownStart);
    } else {
        $this-&gt;mDownStart = 0;
    }
}

/**
 * @access private
 * @return void
 **/
private function setHeader() {
    @header("Cache-control: public");
    @header("Pragma: public");
    header("Content-Length: " . ($this-&gt;mFileSize - $this-&gt;mDownStart));
    if ($this-&gt;mDownStart &gt; 0) {
        @header("HTTP/1.1 206 Partial Content");
        header("Content-Range: bytes " . $this-&gt;mDownStart . "-" . ($this-&gt;mFileSize - 1) . "/" . $this-&gt;mFileSize);
    } else {
        header("Accept-Range: bytes");
    }
    @header("Content-Type: application/octet-stream");
    @header("Content-Disposition: attachment;filename=" . $this-&gt;mFileName);
}

/**
 * @access private
 * @return string
 **/
private function getFileName() {
    return basename($this-&gt;mFilePath);
}

/**
 * @access private
 * @return void
 **/
private function send() {
    // fpassthru($this-&gt;mFileHandle);

    while (!feof($this-&gt;mFileHandle)) {
        set_time_limit(0);
        $buffer = fread($this-&gt;mFileHandle, 1024 * 1024);
        echo $buffer;
        flush();
        ob_flush();
    }
}

/**
 * @access public
 * @return void
 **/
public function sendError() {
    @header("HTTP/1.0 404 Not Found");
    @header("Status: 404 Not Found");
    exit();
}
}
</code></pre>

<p>Here is how I use it,</p>

<pre><code> $transfer = new Transfer;
 $transfer-&gt;Down('D:\Pro lab\Aptana workspace\ezine\ezine\201202161811\VOL_001_201202161811.zip');
</code></pre>

<p>When i try to open two tabs of IE to run the script. But, They could not be downloaded at the same time. They are in the order of one after another.
But, When I put the file in the apache root directory. using still two tabs of IE to download them, they can be downloaded at the same time.
I wonder, Why it happens like that ?</p>

<p>I guess if there is any kind of "lock" in PHP, to limit the same client to download the same resource at same time ??</p>
