Php memory management This post was last edited by zmzkkk from 2012-10-3116: 13: 59. Hello, everyone is working on PHP & nbsp; will the project pay attention to memory management? & Nbsp; I wrote a piece of code to collect a website, CURL & nbsp; collect, & nbsp; MYSQL & nbsp; write a lot of data, I write a record. & Nb php memory management
This post was last edited by zmzkkk at 16:13:59, January 31 ,.
Hello everyone, will you pay attention to memory management when working on PHP projects? I wrote a piece of code to collect a website, CURL collection, MYSQL writes a lot of data, and I write a record. At the beginning of the operation, the collection was fast. However, after a while, the collection speed will be much slower. During the first collection, a memory overflow error occurs about three hours after the program runs. Now that the second collection starts, I used memory_get_usage to record the memory usage during the collection process. Memory usage has been increasing slowly. It has never been released. Another problem is that when I collected the webpage through google browser, I found that the webpage is closed and the collection program is still running. Is there anyone with experience in this area? please advise me. You cannot start garbage collection with gc_collect_cycles.
My php version is 5.4.4
Http://www.zhangmingzun.cn /? P = 144
------ Solution --------------------
Is there an infinite loop collection hanging?
------ Solution --------------------
The unused variables are UNSET after data is added each time. the junk data occupies your memory.
------ Solution --------------------
Is curl collected? is curl released in a loop?
------ Solution --------------------
Curl_close ()
------ Solution --------------------
Unset all unnecessary tasks at the end of each loop,
Then compare it with the memory usage at the beginning of the loop until it is basically the same
This is a slow debugging activity.
Gc_collect_cycles is basically useless, because you will do it without explicitly calling garbage collection.
------ Solution --------------------
Sleep also slows down program running and has nothing to do with memory usage.
You 'd better post your core code for your analysis
------ Solution --------------------
We recommend that you use shell to solve this problem:
The general solution is exec (xx. php, $ args );
In this way, the resources occupied by the xx. php file are directly released after each exec operation.
------ Solution --------------------
You can do this by writing all the code in the $ list loop to another php file, and then directly using the shell background,
------ Solution --------------------
First, read, write, and comment out several tp operations in the loop body to confirm that they are not tp problems.
------ Solution --------------------
Use batch processing.