Recommend this page to a friend! |
Php OBCompress, compresses the Output Buffer In Gzip
This class can compress the output buffer of a web page or web request.
It can start capturing the output buffer of the current HTTP request and compress using the gzip compression method or none based on specified options. The compressed output will be send with the necessary headers back to user browser and optimized. It can process the responses of requests and output data in JSON, HTML, or plain text format faster than regular request output.
Installation is super-easy via Composer:
composer require peterujah/ob-compress
To compress webpage output, see the below example code
<?php
use Peterujah\NanoBlock\OBCompress;
ob_start('OBCompress::ob_strip');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Text OB Compress</title>
</head>
<body>
This will be compress and optimized
</body>
</html>
<?php (new OBCompress())->html(ob_get_contents());
To retrieve data from server it can be done like below
use Peterujah\NanoBlock\OBCompress;
$response = array(
"foo" => "Foo",
"bar" => "Bar"
);
(new OBCompress())->json($response);
Available Response methods
Short Hand to compress data and return as json
$compress->json($data);
Short Hand to compress data and return as plain text
$compress->text($data);
Short Hand to compress data and return as html document
$compress->html($data);
Short Hand to compress data and return as specied content type
$compress->run($data, $contentType);
Strips and minify a webpage content, start output buffer on webpage, place at the beginning of a webpage
$compress->start();
Short Hand to get output buffer of a webpage and compress it then return as spacied data type
$compress->end($contentType);
Rrturns compressed output from passed data, sets the status code and data type
$compress->with($data, $statusCode, $contentType);
A function to strips and minify a webpage content, this can be passed to ob_start('OBCompress::ob_strip');
$compress::ob_strip($content);
Classes of Ujah Chigozie peter | > | PHP Compress JSON, HTML and Text Output | > | ![]() |
> | ![]() |
> | ![]() |
> | ![]() ![]() |
|
Groups | ![]() |
Applications | ![]() |
Groups |
![]() |
HTTP protocol clients, headers and cookies | View top rated classes |
![]() |
Classes using PHP 5 specific features | View top rated classes |
![]() |
Data compression and file archive manipulation | View top rated classes |
Innovation Award |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Doc. | Read me |
![]() NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Doc. | Read me |
![]() NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|