What to use to debug the swoole program
You can use GDB to debug the swoole program. gdb is the abbreviation of GNU debugger, which is a programming debugging tool.
Function of gdb:
1. Start the program and run the program as you like according to user-defined requirements.
2. The debugged program can be stopped at the debugging breakpoint specified by the user (the breakpoint can be a conditional expression).
3. When the program stops, you can check what happened in the program at this time. For example, you can print the value of a variable.
4. Dynamically change the execution environment of the variable program.
Recommended learning: swoole tutorial
How to use gdb to debug swoole:
Enter gdb
gdb php test.php
gdbinit
(gdb) source /path/to/swoole-src/gdbinit
Set breakpoints
For example, co::sleep function
(gdb) b zim_swoole_coroutine_util_sleep
Print all coroutines and status of the current progress
(gdb) co_list coroutine 1 SW_CORO_YIELD coroutine 2 SW_CORO_RUNNING
Print the current run The call stack of the current coroutine
(gdb) co_bt coroutine cid:[2] [0x7ffff148a100] Swoole\Coroutine->sleep(0.500000) [internal function] [0x7ffff148a0a0] {closure}() /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:7 [0x7ffff141e0c0] go(object[0x7ffff141e110]) [internal function] [0x7ffff141e030] (main) /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:10
Print the call stack of the specified coroutine ID
(gdb) co_bt 1 [0x7ffff1487100] Swoole\Coroutine->sleep(0.500000) [internal function] [0x7ffff14870a0] {closure}() /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:3 [0x7ffff141e0c0] go(object[0x7ffff141e110]) [internal function] [0x7ffff141e030] (main) /home/shiguangqi/php/swoole-src/examples/coroutine/exception/test.php:10
Print the status of the serial coroutine
(gdb) co_status stack_size: 2097152 call_stack_size: 1 active: 1 coro_num: 2 max_coro_num: 3000 peak_coro_num: 2
The above is the detailed content of What to use to debug swoole program. For more information, please follow other related articles on the PHP Chinese website!