To read an array about an issue in session

Source: Internet
Author: User
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
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.