[TOC] > [参考](https://juejin.im/entry/5b31aa1bf265da597f1c81c0) ## 安装 `yum install strace` ## 实例 test.php ``` $file = "/var/log/data.log"; $fp = fopen($file, "a"); if ($fp) { echo "start\n"; foreach ($log as $v) { fwrite($fp, $v."\r\n"); } } fclose($fp); ``` `strace -o debug.log php test.php` 输出 ``` lstat("/var/log/data.log", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 lstat("/var/log", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 open("/var/log/data.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 lseek(3, 0, SEEK_CUR) = 0 lseek(3, 0, SEEK_CUR) = 0 write(1, "start\n", 6) = 6 close(3) = 0 close(2) = 0 close(1) = 0 munmap(0x7f7aa7dfd000, 4096) = 0 close(0) = 0 ``` 脚本根本没有运行`fwrite($fp, $v."\r\n");`这段代码 ## 场景 ### 查看运行 pid 的情况 ``` strace -p  29785 -F -p 参数表示跟踪进程 PID 号 -F 表示过程该进程调用的子进程(如 PHP 执行 exec 调用),这是非常重要的一个参数 ```