php 應用 cpu 100% 調試方法

來源:互聯網
上載者:User

標籤:

找出進程佔用cpu高的原因。

進程佔用cpu高,一般是由於進程長時間佔用cpu,又沒有主動釋放佔用。如果想主動釋放cpu,可以調用sleep。在寫程式的時候,尤其要注意while 等迴圈的地方。

找出php進程在執行那段代碼
$sudo gdb -p 10434(gdb) print (char *)executor_globals.active_op_array->filename$13 = 0x2924118 "/home/admin/gearman_manager/pecl-manager.php"(gdb) print executor_globals->current_execute_data->opline->lineno$14 = 55(gdb) cContinuing.^CProgram received signal SIGINT, Interrupt.0x00000031d32306d0 in sigprocmask () from /lib64/libc.so.6(gdb) print executor_globals->current_execute_data->opline->lineno$15 = 71(gdb) cContinuing.^CProgram received signal SIGINT, Interrupt.0x00000000006250e1 in zend_hash_find ()(gdb) print executor_globals->current_execute_data->opline->lineno$16 = 53

如果對上面的命令有疑問,可以查看 當cpu飆升時,找出php中可能有問題的程式碼
根據上面的資訊,我們可以知道,cpu高時,正在執行/home/admin/gearman_manager/pecl-manager.php檔案。並且正在執行53和71行附近的代碼。

 

還可以通過strace進行調試

php 應用 cpu 100% 調試方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.