Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Chunked / Streamed response
#1

(This post was last modified: 08-06-2020, 04:07 AM by marios88.)

Hello

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

Thanks
Reply
#2

(This post was last modified: 08-06-2020, 04:59 AM by jreklund.)

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

Code:
<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
</FilesMatch>

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

-----
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
      do{
          echo $i++.'<br>'.PHP_EOL;
          usleep(50000);
          ob_end_flush();
          if(ob_get_level() > 0) {
              @ob_flush();
          }
          flush();
          ob_start();
      }while($i 20);

Reply




Theme © iAndrew 2016 - Forum software by © MyBB