mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 17:07:03 +03:00
Added AbstractFetchRemote.streamPerLine(fCallback, sGetAdd) for future use of streaming data to the client.
This commit is contained in:
parent
013f09c8d3
commit
20eb01de08
3 changed files with 95 additions and 3 deletions
48
snappymail/v/0.0.0/app/libraries/snappymail/http/stream.php
Normal file
48
snappymail/v/0.0.0/app/libraries/snappymail/http/stream.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace SnappyMail\HTTP;
|
||||
|
||||
/**
|
||||
* Can be used with JavaScript AbstractFetchRemote.streamPerLine(fCallback, sGetAdd)
|
||||
*/
|
||||
|
||||
abstract class Stream
|
||||
{
|
||||
public static function start(bool $binary = false)
|
||||
{
|
||||
\set_time_limit(0);
|
||||
\ob_implicit_flush();
|
||||
\ini_set('implicit_flush',1);
|
||||
\ini_set('output_buffering', 0);
|
||||
if ($i = \ob_get_level()) {
|
||||
# Clear buffers:
|
||||
while ($i-- && \ob_end_clean());
|
||||
// if (!\ob_get_level()) \header('Content-Encoding: ');
|
||||
}
|
||||
// https://www.w3.org/TR/edge-arch/
|
||||
// We just fake Drupal https://www.drupal.org/docs/8/core/modules/big-pipe/bigpipe-environment-requirements
|
||||
\header('Surrogate-Control: no-store, content="BigPipe/1.0"');
|
||||
// Explicitly disable caching so Varnish and other upstreams won't cache.
|
||||
\header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
\header('Pragma: no-cache');
|
||||
|
||||
// Nginx: disable fastcgi_buffering and disable gzip for this request.
|
||||
\header('X-Accel-Buffering: no');
|
||||
|
||||
// Apache mod_fastcgi needs the -flush option
|
||||
// Apache mod_proxy_fcgi needs 'flushpackets' like in <Proxy "fcgi://...." flushpackets=on></Proxy>
|
||||
// We can't control them here
|
||||
// We can control ending the response with \fastcgi_finish_request()
|
||||
|
||||
if (!$binary) {
|
||||
\header('Content-Type: text/plain');
|
||||
}
|
||||
}
|
||||
|
||||
public static function JSON($data)
|
||||
{
|
||||
echo \MailSo\Base\Utils::Php2js($data) . "\n";
|
||||
\ob_flush();
|
||||
\flush();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue