PHP Classes

PHP Compress JSON, HTML and Text Output: Compress the output of the current HTTP response

Recommend this page to a friend!

  Author Author  
Picture of Ujah Chigozie peter
Name: Ujah Chigozie peter <contact>
Classes: 17 packages by
Country: Nigeria Nigeria
Age: 32
All time rank: 229511 in Nigeria Nigeria
Week rank: 514 Up12 in Nigeria Nigeria Down
Innovation award
Innovation award
Nominee: 8x


  Detailed description   Download Download .zip .tar.gz  
This class can compress the output of the current HTTP response.

The class provides a function that the current script can use as a callback function to process the script output to compress it to reduce its size.

It can process the responses of requests that output data in JSON, HTML, or plain text format.

The class also issues HTTP response headers that are adequate for each type of output format.

Details

ob-compress

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

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  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog (1)  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Compress JSON, HTML and Text Output
Base name: ob-compress
Description: Compress the output of the current HTTP response
Version: -
PHP version: 5
License: GNU General Public License (GPL)
All time users: 134 users
All time rank: 9234
Week users: 0 users
Week rank: 177 Equal
 
  Groups   Rate classes User ratings   Applications   Files Files  

  Groups  
Group folder image HTTP HTTP protocol clients, headers and cookies View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Compression Data compression and file archive manipulation View top rated classes


  Innovation Award  
PHP Programming Innovation award nominee
February 2022
Number 4
The HTTP protocol allows compressing the responses to HTTP requests using several algorithms like gzip.

This possibility can make the Web servers respond faster to HTTP requests by reducing the amount transferred to the Web browser, especially when the response is in text formats like HTML, JSON, or plain text.

This package takes advantage of this possibility to reduce the size of HTTP responses generated by PHP scripts.

The package can compress the response data, even more when the output format is HTML because it also compresses HTML by eliminating unnecessary parts, like comments, spaces, and line breaks.

Manuel Lemos

  User ratings  
Not yet rated by the users

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
  Plain text file OBCompress.php Class Class source

Download Download all files: ob-compress.tar.gz ob-compress.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
  Plain text file OBCompress.php Class Class source

Download Download all files: ob-compress.tar.gz ob-compress.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.