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.