The php daemon takes up a lot of memory, so how do I troubleshoot the problem?

problem description

wrote a daemon with the PHP program, which takes up a lot of memory (% MEM:80%) and does not release it.

I can only locate the PID, of this process, but I can"t locate which piece of code in the program caused it. How can I find out what the problem is?

:
- PHP
- 

if it's not too much trouble, you can try my php-stacktrace . There is no need to expand or restart the process. Just a PID, can read the memory of the PHP process, parse the call stack information, and know what the PHP process is doing.

A few dozen ms calls are made to save the result, which is a sample profiler:)

if you read the problem wrong, it turns out that it is a memory problem. You can directly use gdb dump memory and then check it slowly.


If there are not many blocks of

code, use memory_get_usage to print the current memory usage.
php daemons generally have leakage problems, which in many cases are caused by extensions.
so the production environment recommends that every task executed, the counter + 1, when more than a certain amount, such as 100, exit the process, to ensure the complete execution of the business logic (if you quit, it may not be finished)
and then use nodejs's pm2 process to keep alive

.

pm2 configuration file example:

{
  "name": "",
  "script": "cli.php",
  "exec_interpreter": "php",
  "exec_mode": "fork",
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3ef73-58d7d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3ef73-58d7d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?