• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Chunked / Streamed response

#1
Hello

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

Thanks
Reply

#2
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.