PHP Internal Memory Management

Source: Internet
Author: User
PHP Memory Management
This post was last edited by zmzkkk on 2012-10-31 16:13:59

Hello, everyone, when doing PHP project will pay attention to memory management? I wrote a piece of code, collected a website, CURL collection, MYSQL write data more, I am a record write. The collection was fast when it started running. But after a while the acquisition speed will be many times slower. During the first acquisition, the program ran for about three hours with a memory overflow error. Now the second acquisition begins, I use Memory_get_usage to record the memory usage of the acquisition process. Memory usage has been increasing slowly. Has never been released. There is also a problem, I use Google Browser collection, found that the page is closed, the collection program will still be running. Is there anyone who has experience in this area to teach a little brother. Use Gc_collect_cycles () Start garbage collection processing do not know can not.
My PHP version is 5.4.4

http://www.zhangmingzun.cn/?p=144


------Solution--------------------
Is there a collection of infinite loops hanging?
------Solution--------------------
Every time you add the data, you unset the unused variables, and the garbage data takes up your memory.
------Solution--------------------
Curl collection, in the loop, Curl is released?
------Solution--------------------
Curl_close ()

------Solution--------------------
Every time the loop ends, all the unset are not needed,
Then the memory usage at the beginning of the cycle is compared to the basic

It's a slow-commissioning job.

Gc_collect_cycles is basically useless because you don't explicitly call garbage collection to also do
------Solution--------------------
Sleep or slow down the running of the program, nothing to do with memory footprint

You'd better post your core code to help you analyze
------Solution--------------------
It is recommended that you use the shell to solve this problem:
The approximate solution is exec (xx.php, $args);
This frees up the resources occupied by the xx.php file each time the exec finishes running.

------Solution--------------------
Can do this, the $list loop all the code to write to a different PHP file, and then use the shell background directly to it,
------Solution--------------------
First, a few operations of the circulating body TP, including read write, comment out, to confirm the problem is not TP
------Solution--------------------
Then use the batch process.
  • 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.