title: xsendFile downloads have 0 bytes
body: <p>On LAMP stack, I can not get xSendFile to work. The problem is that the downloads have 0 bytes.</p>
  
  <p>In order to be sure that I have xSendFile installed, I have added this to my <code>.htaccess</code> file:</p>
  
  <pre><code>&lt;IfModule mod_xsendfile.c&gt;
    SetEnv MOD_mod_xsendfile 1
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>(I can not test this with <code>apache_get_modules()</code> because I am running PHP as fastCGI.)</p>
  
  <p>I then have the following PHP code:</p>
  
  <pre><code> if (1 != getenv('MOD_mod_xsendfile'))
      {
          echo 'mod_xsendfile is not installed';
      }
      else
      {
          $path = '/home/infar/';
          $file = 'hello.txt';
          if (file_exists($path.$file) &amp;&amp; strlen($path.$file)&gt;1)
          {
              if (true) // change to false to go around Yii
              {
                  Yii::app()-&gt;request-&gt;xSendFile($path.$file,array(
                      'saveName'=&gt; 'hello.txt',
                      'mimeType'=&gt; 'plain/text',
                      'terminate'=&gt; true,
                  ));
              }
              else
              {
                  //set proper Content-Type
                  header('Content-Type: plain/text');
                  //force download box with the filename hello.txt
                  header('Content-Disposition: attachment;filename=hello.txt');
                  header('X-Sendfile: $path.$file');
                  exit;      
              }  
          }
          else
          {
              echo 'file not found at: '.$path.$file;
          }
      }
  </code></pre>
  
  <p>This code runs as expected; from which I conclude that xSendFile must be installed and/or enabled. I then run this script both with Yii <code>xSendFile</code> and with plain PHP. In both cases the download window opens, but always with 0 bytes.</p>
  
  <p>I am at my wits' end. <strong>What am I doing wrong?</strong></p>
  
  <p>In the interest of full disclosure, here is the relevant part of <code>httpd.conf</code>:</p>
  
  <pre><code>&lt;IfModule mod_xsendfile.c&gt;
      XSendFile on
      XSendFilePath /home/infar
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Output compression is turned off:</p>
  
  <pre><code>ini_get("zlib.output_compression"); // returns "Off"
  </code></pre>
  
  <p>Chrome shows me the following headers:</p>
  
  <pre><code>Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  Connection:Keep-Alive
  Content-Disposition:attachment;filename=hello.txt
  Content-Length:0
  Content-Type:plain/text
  Date:Sun, 23 Mar 2014 18:22:49 GMT
  Expires:Thu, 19 Nov 1981 08:52:00 GMT
  Keep-Alive:timeout=2, max=100
  Pragma:no-cache
  Server:Apache
  X-Sendfile:/home/infar/hello.txt
  </code></pre>
  
  <p><strong>Update March 26th, 2014</strong></p>
  
  <p>When testing @gabrieloliveira suggestion, I discovered the following:</p>
  
  <pre><code>header('Content-Type: plain/text');
  header('Content-Disposition: attachment;filename=hello.txt');
  header('X-Sendfile: '.$path.$file); // $path.$file outside quotes
  header('Content-Length: '.filesize($path.$file)); // Filesize
  echo '12345678901234567890';
  exit;  
  </code></pre>
  
  <p>This script (where I have added <code>echo '12345678901234567890';</code>) produced a download for a file containing the following 16 character string <code>1234567890123456</code>. 16 characters matches the filesize of <code>hello.txt</code>. So it seems we can conclude the following</p>
  
  <ol>
  <li>Content-Length &amp; Filesize are handled correctly.</li>
  <li>Either X-SendFile does not find the file, or:</li>
  <li>X-SendFile does not process the file.</li>
  </ol>
  
  <p>In fact, commenting out X-SendFile, like so:</p>
  
  <pre><code>// header('X-Sendfile: '.$path.$file);
  </code></pre>
  
  <p>produces the same result; indiscernible from executing the <code>X-Sendfile</code> header.</p>