PHP long-running daemon script memory overflow, to the great God analysis.

Source: Internet
Author: User
The system runs a long-running daemon script that scans the Redis queue every minute and enters logic when the condition is met, but every time it three hours, the system will get an error.

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /data/Db.php on line 150

Check the number of frequent error lines, found that most of the PDO's execute or Fetch_all method error.
At the beginning of the SQL query is a problem, looked at the SQL statement is generally used with limit to take 10 records, and if it is a query statement problem will only make the query slow, not overflow ah.

Read the online information, most people say is to actively recycle memory, that is, using unset to use the object or variable to recycle. However, as a process, its logic is the same every time, and then the variable or object even if it is not recycled, it will be the next logical requirement of the same name variable overwrite Ah, if the first logic run through, the back should not overflow ah.

Ask the great God to help analyze my ideas where there is a problem, thank you.

Reply content:

The system runs a long-running daemon script that scans the Redis queue every minute and enters logic when the condition is met, but every time it three hours, the system will get an error.

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /data/Db.php on line 150

Check the number of frequent error lines, found that most of the PDO's execute or Fetch_all method error.
At the beginning of the SQL query is a problem, looked at the SQL statement is generally used with limit to take 10 records, and if it is a query statement problem will only make the query slow, not overflow ah.

Read the online information, most people say is to actively recycle memory, that is, using unset to use the object or variable to recycle. However, as a process, its logic is the same every time, and then the variable or object even if it is not recycled, it will be the next logical requirement of the same name variable overwrite Ah, if the first logic run through, the back should not overflow ah.

Ask the great God to help analyze my ideas where there is a problem, thank you.

Scan every minute why not make crontab, so every time after execution exit, should not encounter memory problems it?

Can try to monitor the memory in each row of the changes, after two cycles to look at, have tried before in a loop even if the variable is released or will slowly increment up the memory consumption

Limit script memory consumption and time-out

  • 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.