Skip to content

Commit

Permalink
Allowed not to exit after zEcho
Browse files Browse the repository at this point in the history
  • Loading branch information
Simbiat committed Dec 25, 2021
1 parent db43784 commit 4044858
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doc/Common.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/HTTP20/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 4044858

Please sign in to comment.