commit a71ed489a2eea704d732cb2f1d11754dac26e84a Author: Joshua Seigler Date: Thu Jun 30 11:58:42 2016 -0400 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab3517c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# https://git-scm.com/docs/gitignore +# https://help.github.com/articles/ignoring-files +# Example .gitignore files: https://github.com/github/gitignore diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..70d06e9 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Joshua Seigler + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6cd1e15 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# 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/ + diff --git a/buffer.php b/buffer.php new file mode 100644 index 0000000..f602152 --- /dev/null +++ b/buffer.php @@ -0,0 +1,71 @@ +