diff --git a/doc/Common.md b/doc/Common.md index 8f8d7e4..5157db2 100644 --- a/doc/Common.md +++ b/doc/Common.md @@ -28,10 +28,11 @@ Function to prepare ID for Atom feed as suggested on http://web.archive.org/web/ ## zEcho ```php -zEcho(string $string, string $cacheStrat = ''); +zEcho(string $string, string $cacheStrat = '', bool $exit = true); ``` A function for outputting data to web-browser while attempting to use compression, if available, and providing `Content-Length` header. In terms of compression, it will check whether `zlib` extension is loaded, then check if `zlib.output_compression` is `'On'`. If `zlib` is enabled, but compression is not enabled globally, it will use `ob_gzhandler` and add header, if not - just use the buffer and send the data. If `zlib` is not loaded, will not use compression, but will use buffer to provide proper header. The goal of the function is more standardization of the output, in case you have different settings on different environments for some reason. `$cacheStrat` is an optional caching strategy to apply (as described for [cacheControl](doc/Headers.md#cachecontrol)) +`$exit` allows to cancel automatic exit of the script (default), in case you want to do some more processing even after the page is pushed to client. ## emailValidator ```php diff --git a/src/HTTP20/Common.php b/src/HTTP20/Common.php index d66f349..d4dba34 100644 --- a/src/HTTP20/Common.php +++ b/src/HTTP20/Common.php @@ -783,7 +783,7 @@ public function atomIDGen(string $link, string|int|float|null $date = NULL): str } #Function utilizes ob functions to attempt compressing output sent to browser and also provide browser with length of the output and some caching-related headers - public function zEcho(string $string, string $cacheStrat = ''): void + public function zEcho(string $string, string $cacheStrat = '', bool $exit = true): void { #Close session if (session_status() === PHP_SESSION_ACTIVE) { @@ -806,7 +806,9 @@ public function zEcho(string $string, string $cacheStrat = ''): void } #Send the output echo $string; - exit; + if ($exit) { + exit; + } } #Function to check if string is a mail address as per RFC 5322 @@ -1036,9 +1038,9 @@ public function forceClose(): void #Send header to notify, that connection was closed @header('Connection: close'); #Clean output buffer and close it - ob_end_clean(); + @ob_end_clean(); #Clean system buffer - flush(); + @flush(); exit; } }