mirror of
https://github.com/seigler/simple-php-buffering
synced 2025-07-27 01:36:13 +00:00
28 lines
893 B
Markdown
28 lines
893 B
Markdown
# seigler/simple-php-buffer
|
|
|
|
PHP file for basic file-based output buffering
|
|
|
|
## Usage
|
|
```php
|
|
define('CACHE_PATH', sys_get_temp_dir().'/cache_'); // optional, cache-file location prefix
|
|
define('CACHE_TIME', 5 * 60); // optional, seconds to cache the output
|
|
require 'buffer.php';
|
|
```
|
|
|
|
This will send last-modified, expires, and etag headers. If a request includes theetag and
|
|
modified-since parameters the script can return a 304 not modified.
|
|
|
|
This uses output buffering, but it can't buffer headers. If you need to send out a header every time, cached or not, put that header code above the `require`.
|
|
|
|
```php
|
|
Header('Content-type: image/svg+xml; charset=utf-8');
|
|
Header('Content-Disposition: inline; filename="fancy-chart-' . date('Y-m-d\THisT') . '.svg"');
|
|
require 'buffer.php';
|
|
|
|
// remaining code to generate the chart
|
|
```
|
|
|
|
## Credits
|
|
|
|
* Based on http://www.the-art-of-web.com/php/buffer/
|
|
|