Skip to content

inplayo-com/pakojs-php-zlib-fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

preview

Demo: pako.js + php zlib (fetch version)

Project demonstrate ability compress client (browser) -> server request using pako.js and default zlib php library.

Code

Client side (browser)

//https://cdnjs.cloudflare.com/ajax/libs/pako/2.1.0/pako.min.js

const data = {a: 1, b: 2} //request data
fetch("server/decompress.php", {
  method: "POST",
  headers: {
    "Content-Type": "text/plain;charset=UTF-8",
  },
  body: pako.deflate(JSON.stringify(data)),
});

Server side

$data = file_get_contents('php://input');
$data = json_decode(zlib_decode($data));
var_dump($data);

Tests

Tests performed using compression functional and non-compressed requests. Images below are screenshots from google chrome network inspector after requests done.

Request data 344b

preview

Request data 2.5mb

preview

Request data 5mb

preview

Request data 7.5mb

preview

Request data 10mb

preview

Environment

  • PHP 7.2.34
  • pako.js 2.1.0
  • Google Chrome 107.0.5304.110 (Official Build) (x86_64)

Contributors

Made with contributors-img.