Reading array Problems in session
This post was last edited by zl2727 on 2013-12-26 16:50:24
$query = "SELECT * from #@__arctype where isbaike=1";
$this->dsql->execute ("Bkarry", $query);
$bkarry =array ();
Session_Start ();
if (!session_is_registered ("Bkarry")) {
while ($row 2 = $this->dsql->getarray ("Bkarry"))
{
$bkarry []= $row 2;
}
$bkarry 2=serialize ($bkarry);
$_session[' Bkarry ']= $bkarry 2;
}else{
$bkarry =unserialize ($_session[' Bkarry ');
}
unset ($_session[' Bkarry ');
Var_dump ($bkarry);
while ($row = $bkarry)
{var_dump ($row);
}
Exit ();
When you remove an array from the session, you can't recycle the report. Insufficient memory
Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate 1176 bytes)
Heroes, help to see what's wrong or easier to write.
I want to implement query data there are more than 3,000 times every time the search is too slow, so want to save to the session call not every time to check
Share to: more
------Solution--------------------
The problem is not the session access, but the processing after reading!
It's a dead loop.
while ($row = $bkarry) {
Var_dump ($row);
}
But this does not cause memory shortage, you should point out where the memory is low
Session_Start ();
$query = "SELECT * from #@__arctype where isbaike=1";
if (! isset ($_session[' Bkarry ')) {
$this->dsql->execute ("Bkarry", $query);
while ($row 2 = $this->dsql->getarray ("Bkarry"))
{
$_session[' Bkarry ' [] = $row 2;
}
}
$bkarry =& $_session[' Bkarry '];
The session itself is serialized and does not need to be serialized by itself. And the string after the session serialization is much shorter than the serialize.
Makes $bkarry a reference to $_session[' Bkarry '), and can reduce memory by half