PHP using ob_start() to compress json array didn't affect reception speed on users laptop











up vote
-1
down vote

favorite












I need to compress a large json array (around 30 000 rows). After searching I found this answer on stack proposing to use ob_start() to compress the json array.



After reading the documentation of ob_start(), we should use to other functions in order to properly compress and return the result, which are:



ob_get_contents();
ob_end_flush();


The function I have is:



public function getDataByType($conn, $dataType)
{
try
{
$result=array();

if($dataType=='household')
{
$sql = "SELECT h.household_id, u.unit_id, h.hh_last_name_en,
h.hh_last_name_ar, h.hh_number_of_ind FROM unit u
INNER JOIN household h
ON u.unit_id=h.unit_id
LEFT JOIN location l
ON l.location_id_auto=u.location_id_auto
LEFT JOIN user us
ON us.user_id = h.user_id
";
$exec = $this->conn->prepare($sql);
$exec->execute();
$result = $exec->fetchAll();
//$count = $exec->rowCount();
}
if($dataType=='individual')
{

}
return $result;
}
catch(PDOException $e)
{
return $e->getMessage();
}
ob_start("getDataByType");
$result = ob_get_contents();
ob_end_flush();

}


I didn't notice any change in the speed of array display on user screen, it took about 5 seconds, and still taking the same time, even more than that sometimes.



No errors shown.



I am using PHP with angular 6, and we are working locally on a LAN network.



I remove the ob_start() from the api file, and use it on from the call script according to this answer on stack:



$dataType = $_POST['dataType'];

ob_start("getDataByType");
$res = $newApi->getDataByType($conn, $dataType);
$res = ob_get_clean();
echo json_encode($res);


Why ob_start() is not compressing the json array returned, as it's having the same original uncompressed size.



This answer helped me but still didn't notice any difference on speed or json size.



EDIT



I used the following with each JSON return:



echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


It reduced all sizes for nearly 20%.



Using the following didn't change it:



ob_start('ob_gzhandler');
$res = $newApi->getDataByType($conn, $dataType);
ob_get_clean();
echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


According to this documentation, setting these lines to On didn't do that much for me:



ini_set("zlib.output_compression", 1);
ini_set("zlib.output_compression_level", 9);









share|improve this question
























  • So your question is? (Not my downvote)
    – Lithilion
    Nov 7 at 8:06












  • I am editing the question. So please don't downvote
    – alim1990
    Nov 7 at 8:08










  • @Lithilion you can check the question and remove the downvote please.
    – alim1990
    Nov 7 at 8:11






  • 2




    Possible duplicate of How to compress JSON with PHP?
    – Nick
    Nov 7 at 8:13










  • @Nick apparently you didn't read my question and check that I already added the link of this question, which it helps, but I didn't notice any change on speed or json size.
    – alim1990
    Nov 7 at 9:08















up vote
-1
down vote

favorite












I need to compress a large json array (around 30 000 rows). After searching I found this answer on stack proposing to use ob_start() to compress the json array.



After reading the documentation of ob_start(), we should use to other functions in order to properly compress and return the result, which are:



ob_get_contents();
ob_end_flush();


The function I have is:



public function getDataByType($conn, $dataType)
{
try
{
$result=array();

if($dataType=='household')
{
$sql = "SELECT h.household_id, u.unit_id, h.hh_last_name_en,
h.hh_last_name_ar, h.hh_number_of_ind FROM unit u
INNER JOIN household h
ON u.unit_id=h.unit_id
LEFT JOIN location l
ON l.location_id_auto=u.location_id_auto
LEFT JOIN user us
ON us.user_id = h.user_id
";
$exec = $this->conn->prepare($sql);
$exec->execute();
$result = $exec->fetchAll();
//$count = $exec->rowCount();
}
if($dataType=='individual')
{

}
return $result;
}
catch(PDOException $e)
{
return $e->getMessage();
}
ob_start("getDataByType");
$result = ob_get_contents();
ob_end_flush();

}


I didn't notice any change in the speed of array display on user screen, it took about 5 seconds, and still taking the same time, even more than that sometimes.



No errors shown.



I am using PHP with angular 6, and we are working locally on a LAN network.



I remove the ob_start() from the api file, and use it on from the call script according to this answer on stack:



$dataType = $_POST['dataType'];

ob_start("getDataByType");
$res = $newApi->getDataByType($conn, $dataType);
$res = ob_get_clean();
echo json_encode($res);


Why ob_start() is not compressing the json array returned, as it's having the same original uncompressed size.



This answer helped me but still didn't notice any difference on speed or json size.



EDIT



I used the following with each JSON return:



echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


It reduced all sizes for nearly 20%.



Using the following didn't change it:



ob_start('ob_gzhandler');
$res = $newApi->getDataByType($conn, $dataType);
ob_get_clean();
echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


According to this documentation, setting these lines to On didn't do that much for me:



ini_set("zlib.output_compression", 1);
ini_set("zlib.output_compression_level", 9);









share|improve this question
























  • So your question is? (Not my downvote)
    – Lithilion
    Nov 7 at 8:06












  • I am editing the question. So please don't downvote
    – alim1990
    Nov 7 at 8:08










  • @Lithilion you can check the question and remove the downvote please.
    – alim1990
    Nov 7 at 8:11






  • 2




    Possible duplicate of How to compress JSON with PHP?
    – Nick
    Nov 7 at 8:13










  • @Nick apparently you didn't read my question and check that I already added the link of this question, which it helps, but I didn't notice any change on speed or json size.
    – alim1990
    Nov 7 at 9:08













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I need to compress a large json array (around 30 000 rows). After searching I found this answer on stack proposing to use ob_start() to compress the json array.



After reading the documentation of ob_start(), we should use to other functions in order to properly compress and return the result, which are:



ob_get_contents();
ob_end_flush();


The function I have is:



public function getDataByType($conn, $dataType)
{
try
{
$result=array();

if($dataType=='household')
{
$sql = "SELECT h.household_id, u.unit_id, h.hh_last_name_en,
h.hh_last_name_ar, h.hh_number_of_ind FROM unit u
INNER JOIN household h
ON u.unit_id=h.unit_id
LEFT JOIN location l
ON l.location_id_auto=u.location_id_auto
LEFT JOIN user us
ON us.user_id = h.user_id
";
$exec = $this->conn->prepare($sql);
$exec->execute();
$result = $exec->fetchAll();
//$count = $exec->rowCount();
}
if($dataType=='individual')
{

}
return $result;
}
catch(PDOException $e)
{
return $e->getMessage();
}
ob_start("getDataByType");
$result = ob_get_contents();
ob_end_flush();

}


I didn't notice any change in the speed of array display on user screen, it took about 5 seconds, and still taking the same time, even more than that sometimes.



No errors shown.



I am using PHP with angular 6, and we are working locally on a LAN network.



I remove the ob_start() from the api file, and use it on from the call script according to this answer on stack:



$dataType = $_POST['dataType'];

ob_start("getDataByType");
$res = $newApi->getDataByType($conn, $dataType);
$res = ob_get_clean();
echo json_encode($res);


Why ob_start() is not compressing the json array returned, as it's having the same original uncompressed size.



This answer helped me but still didn't notice any difference on speed or json size.



EDIT



I used the following with each JSON return:



echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


It reduced all sizes for nearly 20%.



Using the following didn't change it:



ob_start('ob_gzhandler');
$res = $newApi->getDataByType($conn, $dataType);
ob_get_clean();
echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


According to this documentation, setting these lines to On didn't do that much for me:



ini_set("zlib.output_compression", 1);
ini_set("zlib.output_compression_level", 9);









share|improve this question















I need to compress a large json array (around 30 000 rows). After searching I found this answer on stack proposing to use ob_start() to compress the json array.



After reading the documentation of ob_start(), we should use to other functions in order to properly compress and return the result, which are:



ob_get_contents();
ob_end_flush();


The function I have is:



public function getDataByType($conn, $dataType)
{
try
{
$result=array();

if($dataType=='household')
{
$sql = "SELECT h.household_id, u.unit_id, h.hh_last_name_en,
h.hh_last_name_ar, h.hh_number_of_ind FROM unit u
INNER JOIN household h
ON u.unit_id=h.unit_id
LEFT JOIN location l
ON l.location_id_auto=u.location_id_auto
LEFT JOIN user us
ON us.user_id = h.user_id
";
$exec = $this->conn->prepare($sql);
$exec->execute();
$result = $exec->fetchAll();
//$count = $exec->rowCount();
}
if($dataType=='individual')
{

}
return $result;
}
catch(PDOException $e)
{
return $e->getMessage();
}
ob_start("getDataByType");
$result = ob_get_contents();
ob_end_flush();

}


I didn't notice any change in the speed of array display on user screen, it took about 5 seconds, and still taking the same time, even more than that sometimes.



No errors shown.



I am using PHP with angular 6, and we are working locally on a LAN network.



I remove the ob_start() from the api file, and use it on from the call script according to this answer on stack:



$dataType = $_POST['dataType'];

ob_start("getDataByType");
$res = $newApi->getDataByType($conn, $dataType);
$res = ob_get_clean();
echo json_encode($res);


Why ob_start() is not compressing the json array returned, as it's having the same original uncompressed size.



This answer helped me but still didn't notice any difference on speed or json size.



EDIT



I used the following with each JSON return:



echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


It reduced all sizes for nearly 20%.



Using the following didn't change it:



ob_start('ob_gzhandler');
$res = $newApi->getDataByType($conn, $dataType);
ob_get_clean();
echo json_encode($res, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK );


According to this documentation, setting these lines to On didn't do that much for me:



ini_set("zlib.output_compression", 1);
ini_set("zlib.output_compression_level", 9);






php json compression encode ob-start






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 10:11

























asked Nov 7 at 8:00









alim1990

89011231




89011231












  • So your question is? (Not my downvote)
    – Lithilion
    Nov 7 at 8:06












  • I am editing the question. So please don't downvote
    – alim1990
    Nov 7 at 8:08










  • @Lithilion you can check the question and remove the downvote please.
    – alim1990
    Nov 7 at 8:11






  • 2




    Possible duplicate of How to compress JSON with PHP?
    – Nick
    Nov 7 at 8:13










  • @Nick apparently you didn't read my question and check that I already added the link of this question, which it helps, but I didn't notice any change on speed or json size.
    – alim1990
    Nov 7 at 9:08


















  • So your question is? (Not my downvote)
    – Lithilion
    Nov 7 at 8:06












  • I am editing the question. So please don't downvote
    – alim1990
    Nov 7 at 8:08










  • @Lithilion you can check the question and remove the downvote please.
    – alim1990
    Nov 7 at 8:11






  • 2




    Possible duplicate of How to compress JSON with PHP?
    – Nick
    Nov 7 at 8:13










  • @Nick apparently you didn't read my question and check that I already added the link of this question, which it helps, but I didn't notice any change on speed or json size.
    – alim1990
    Nov 7 at 9:08
















So your question is? (Not my downvote)
– Lithilion
Nov 7 at 8:06






So your question is? (Not my downvote)
– Lithilion
Nov 7 at 8:06














I am editing the question. So please don't downvote
– alim1990
Nov 7 at 8:08




I am editing the question. So please don't downvote
– alim1990
Nov 7 at 8:08












@Lithilion you can check the question and remove the downvote please.
– alim1990
Nov 7 at 8:11




@Lithilion you can check the question and remove the downvote please.
– alim1990
Nov 7 at 8:11




2




2




Possible duplicate of How to compress JSON with PHP?
– Nick
Nov 7 at 8:13




Possible duplicate of How to compress JSON with PHP?
– Nick
Nov 7 at 8:13












@Nick apparently you didn't read my question and check that I already added the link of this question, which it helps, but I didn't notice any change on speed or json size.
– alim1990
Nov 7 at 9:08




@Nick apparently you didn't read my question and check that I already added the link of this question, which it helps, but I didn't notice any change on speed or json size.
– alim1990
Nov 7 at 9:08

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185468%2fphp-using-ob-start-to-compress-json-array-didnt-affect-reception-speed-on-use%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185468%2fphp-using-ob-start-to-compress-json-array-didnt-affect-reception-speed-on-use%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini