title: How to disable output buffering for Laravel
body: <p>I have this function in controller ImportController.php, I seding a file to import using the <a href="https://laravel-excel.com/" rel="nofollow noreferrer">Laravel Excel</a> library...</p>
  
  <ul>
  <li>Laravel version: <code>5.5</code></li>
  <li>Php Version: <code>PHP 7.2.19-0ubuntu0.18.10.1 (cli) (built: Jun  4 2019 14:46:43) ( NTS )</code></li>
  </ul>
  
  <p>One sheet the client is sending is taking a lot of time. Then I make a progress bar for the client get a feedback when is importing/saving data from the sheet.</p>
  
  <ul>
  <li>This is the javascript function here is sending the sheet and token and if is a ajax request.</li>
  </ul>
  
  <pre class="lang-js prettyprint-override"><code>.....
              let fd = new FormData();
              fd.append(_archiveInputId, archivoSeleccionado.files[0]);
              fd.append("_token", window.Laravel.csrfToken);
              fd.append("isHttpRequest", true);
  
              let xmlHTTP = new XMLHttpRequest();
  
              xmlHTTP.upload.addEventListener("progress", progressFunction, false);
              xmlHTTP.addEventListener("load", transferCompleteFunction, false);
              xmlHTTP.addEventListener("error", uploadFailed, false);
              xmlHTTP.addEventListener("abort", uploadCanceled, false);
              xmlHTTP.responseType = 'json';
              xmlHTTP.response = 'json';
              xmlHTTP.open("POST", _url, true);
              xmlHTTP.send(fd);
  
  .....
  
          /**
           * Progress Function
           * @param evt
           */
          function progressFunction(evt) {
              console.log(evt);
          }
  </code></pre>
  
  <ul>
  <li>This is my controller:</li>
  </ul>
  
  <pre class="lang-php prettyprint-override"><code>public function import(ImportFormRequest $request)
  {
          $isHttpRequest = $request-&gt;has('isHttpRequest') ? $request-&gt;has('isHttpRequest') : false;
  
          if($isHttpRequest){
              echo "creating EventsImport class";
              flush();
              sleep(1);
          }
  
          $import = new EventsImport(EventsImport::TYPE_SIMPLE, $request-&gt;file('sheet'));
          try{
              if($isHttpRequest){
                  echo "importing data from sheet";
                  flush();
                  sleep(1);
              }
              Excel::import($import, $request-&gt;file('sheet'));
          }catch (\Exception $e){
              return $this-&gt;returnJsonResponseHttpRequest("nok","Erro ao realizar importação! Erro: ".$e-&gt;getMessage());
          }
  }
  </code></pre>
  
  <p>These outputs <code>echo "importing data from sheet"</code> is for testing.</p>
  
  <p>I tried with:</p>
  
  <ul>
  <li><code>ob_flush();</code></li>
  <li><code>flush();</code></li>
  <li><code>php.ini -&gt; output_buffering=Off</code></li>
  <li><code>.htaccess -&gt; mod_env.c -&gt; SetEnv no-gzip 1</code></li>
  </ul>
  
  <p>But none worked (in laravel). In tests outside Laravel ob_flush and flush works fine.</p>
  
  <p>Anyone have any idea?</p>