make a API in PHP which accept Request / response Zipped, gziped, deflate -
i working on api development using php, need function request encoding , set reponse based on encoding "zipped", "gziped", "deflate" etc, , output should in json.
i trying use below code, when run causing error "this webpage not available\n err_content_decoding_failed"
so, please suggest 1 how can implement such thing.
function converttoheaderencoding($input, $encoding, $debug = 0) { $compressed_out = ""; if($encoding == "gzip") { $compressed_out = gzencode($input); if($debug == 1) echo 'gzipd output'."\n".'before compression size '.strlen($output).' bytes'."\n".' after compression size '.strlen($compressed_out).' bytes'; header("content-encoding: gzip"); return $compressed_out; } else return $input; }
$arr = array("key1"=>"i find works well, save snip below in php/ directory edit prepend.php file , add require statement requires compression.php file below. once complete watch (tail -f) php error log see results of compression in action. find works well, save snip below in php/ directory edit prepend.php file , add require statement requires compression.php file below. once complete watch (tail -f) php error log see results of compression in action. find works well, save snip below in php/ directory edit prepend.php file , add require statement requires compression.php file below. once complete watch (tail -f) php error log see results of compression in action");
$jsonstring = json_encode($arr, true); $output = converttoheaderencoding($jsonstring, "gzip", 1); echo $output;
i'm not sure whether code can work way. try solution:
// turn on output buffering gzhandler ob_start('ob_gzhandler'); // output normal echo json_encode($data);
Comments
Post a Comment