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);
php json compression encode ob-start
|
show 5 more comments
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);
php json compression encode ob-start
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
|
show 5 more comments
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);
php json compression encode ob-start
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
php json compression encode ob-start
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
|
show 5 more comments
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
|
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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