CodeIgniter Forums

Full Version: [SOLVED] Chunked / Streamed response
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Is there a recommended way to send chunked or streaming responses from the controller?

That was actually easy, problem was with apache and php-fpm, make sure you have flushpackets=auto in your virtualhost conf

<FilesMatch \.php$>
  SetHandler proxy:fcgi://localhost:9000
  # for Unix sockets, Apache 2.4.10 or higher
  # SetHandler proxy:unix:/path/to/fpm.sock|fcgi://dummy

<Proxy "fcgi://localhost:9000" flushpackets=auto flushwait=10>

example controller

PHP Code:
public function test(){
      $this->session->regenerate(true); // test cookies are sent
      $i 0;
      $this->response->setHeader('header-forced','1'); //example add header
      $this->response->setBody(''); // clear body
      $this->response->send(); // sends headers and cookies
      $this->session->close(); //session_write_close()
//long running task
          echo $i++.'<br>'.PHP_EOL;
          if(ob_get_level() > 0) {
      }while($i 20);