Operations 4 min read

Diagnosing High CPU Usage in PHP Processes with strace

This article demonstrates how to use strace, including its -c, -T, and -e options, to identify kernel‑level system calls such as clone that cause high CPU consumption in PHP processes on a Linux server, providing step‑by‑step commands and interpretation of the results.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
Diagnosing High CPU Usage in PHP Processes with strace

In earlier days knowing the strace command was impressive; today it is a common tool for diagnosing performance problems. When a high‑load server shows most CPU time spent in kernel mode ("sy"), strace becomes the appropriate utility to trace system calls.

The article presents a real case where the top output reveals several PHP processes consuming CPU, while memory and swap are not critical. Since the CPU usage appears in kernel space, the author suggests using strace to investigate.

Basic attachment: shell> strace -p <PID>

Because raw output can be overwhelming, the -c option aggregates time per syscall: shell> strace -cp <PID>

The aggregated result shows that the clone syscall dominates CPU time. To examine this call in detail, the following command is used: shell> strace -T -e clone -p <PID>

The -T flag reports the actual time each syscall takes, and -e clone filters for the clone operation. The output indicates that a single clone call can take several hundred milliseconds.

According to the manual, clone creates a new process. In PHP, such a system call often originates from the exec function. The article verifies this with: shell> strace -eclone php -r 'exec("ls");'

Thus, the high CPU usage is traced back to PHP code invoking exec , which triggers a costly clone system call. The article concludes with this practical debugging workflow for Linux operations.

operationsLinuxPHPPerformance Debuggingsystem callsstrace
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.