{"id":1179,"date":"2026-09-19T22:01:59","date_gmt":"2026-09-19T22:01:59","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/"},"modified":"2026-09-19T22:01:59","modified_gmt":"2026-09-19T22:01:59","slug":"profiling-php-fpm-slowlog-strace-bottlenecks","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/","title":{"rendered":"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When a page takes 1.8 seconds and CPU sits at 40 percent, the problem is not capacity &mdash; it is latency somewhere in the request path. Guessing at it means changing PHP settings randomly and hoping. Profiling means measuring which of the three possible causes is real: an external call (DNS, HTTP, database), a lock\/blocking wait, or genuine CPU work. This deep dive walks through the tooling on a 2026 Ubuntu 24.04 VPS running PHP 8.4-FPM.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Turn On the PHP-FPM Slow Log<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The slow log records the full PHP stack of any request exceeding a threshold. It costs a negligible amount when idle and is the single highest-value diagnostic setting available.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/php\/8.4\/fpm\/pool.d\/www.conf\nrequest_slowlog_timeout = 2s\nslowlog = \/var\/log\/php8.4-fpm-slow.log\nrequest_terminate_timeout = 60s\nrequest_slowlog_trace_depth = 30<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set the threshold at roughly 3&times; your p95 response time. On a site whose p95 is 400 ms, a 2 s threshold captures only genuinely pathological requests instead of flooding the log.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl reload php8.4-fpm\ntail -f \/var\/log\/php8.4-fpm-slow.log<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A representative entry looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[20-Sep-2026 11:04:22]  [pool www] pid 41207\nscript_filename = \/var\/www\/site\/public\/index.php\n[0x00007f] curl_exec() \/var\/www\/site\/vendor\/guzzle\/src\/Handler\/CurlHandler.php:44\n[0x00008a] sendAsyncRequest() \/var\/www\/site\/vendor\/guzzle\/src\/Client.php:190\n[0x000131] request() \/var\/www\/site\/app\/Services\/PricingApi.php:88\n[0x0001c9] quote() \/var\/www\/site\/app\/Http\/ProductController.php:57<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Read it bottom-up. The framework entry point is the controller; the deepest frame is where time is being burned. Here it is <code>curl_exec()<\/code> inside an outbound API call &mdash; no amount of PHP tuning will help. The fix is a timeout and a cache, not more workers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Classify the Bottleneck Before You Touch Config<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Slow-log top frame<\/th><th>Class<\/th><th>Correct response<\/th><\/tr><\/thead><tbody><tr><td><code>curl_exec<\/code>, <code>stream_socket_client<\/code><\/td><td>Network I\/O wait<\/td><td>Timeout + cache; never add workers<\/td><\/tr><tr><td><code>PDOStatement::execute<\/code><\/td><td>Database latency<\/td><td>Index work, buffer pool sizing<\/td><\/tr><tr><td><code>file_get_contents<\/code>, <code>include<\/code><\/td><td>Disk I\/O \/ missing opcache<\/td><td>Enable opcache, check realpath cache<\/td><\/tr><tr><td><code>sleep<\/code>, <code>flock<\/code>, <code>sem_acquire<\/code><\/td><td>Lock contention<\/td><td>Move sessions out of files, remove locks<\/td><\/tr><tr><td>Deep in your own application code<\/td><td>Genuine CPU<\/td><td>Profile with a sampling profiler<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This table is the whole diagnostic method. Four of the five classes look identical from the outside &mdash; a slow page and idle CPU &mdash; but only the last one is fixed by tuning PHP itself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Confirm With strace on a Single PID<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To prove a network wait, attach to one FPM worker and look at the syscall timing. Never run this on all workers at once &mdash; <code>strace<\/code> multiplies syscall overhead and will distort your own measurement.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># find a worker currently handling a request\npgrep -af 'php-fpm: pool www'\n\n# trace it, showing only slow syscalls\nsudo strace -f -T -e trace=network,read,write -p 41207 2&gt;&amp;1 | awk '{ if ($NF ~ \/\\.\/ ) print }'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>-T<\/code> flag appends the duration of each syscall in seconds. A <code>recvfrom()<\/code> or <code>poll()<\/code> sitting at <code>&lt;1.2&gt;<\/code> while the socket is idle is conclusive proof of remote latency. If instead you see a high volume of fast syscalls, the process is genuinely CPU-bound.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the slow-log frames point at <code>PDOStatement::execute<\/code>, the investigation moves to MySQL, and the arithmetic laid out in <a href=\"https:\/\/virtualserversvps.com\/blog\/mysql-innodb-buffer-pool-sizing-1gb-vps\">sizing the InnoDB buffer pool for a 1 GB VPS<\/a> is the first thing to check, because a buffer pool smaller than the working set turns every read into a disk seek.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: A Minimal In-Process Timing Harness<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Slow logs give you the worst offenders. To get a distribution you need something in-process. A 20-line wrapper is often more useful than a full APM install on a small VPS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function timed(string $label, callable $fn) {\n    $t0 = hrtime(true);\n    $out = $fn();\n    $ms = (hrtime(true) - $t0) \/ 1e6;\n    error_log(sprintf('TIMING %-24s %8.2f ms', $label, $ms));\n    return $out;\n}\n\n$rows = timed('db.products', fn() =&gt; $pdo-&gt;query('SELECT * FROM products')-&gt;fetchAll());\n$rate = timed('http.pricing', fn() =&gt; $client-&gt;quote($id));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>hrtime(true)<\/code> returns nanoseconds from a monotonic clock and is unaffected by NTP steps &mdash; unlike <code>microtime()<\/code>, it cannot produce a negative duration when chrony slews the clock. Aggregate the log lines with a one-liner to get mean and p95 per label:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep TIMING \/var\/log\/php8.4-fpm.log \\\n  | awk '{sum[$3]+=$4; n[$3]++; if($4&gt;max[$3])max[$3]=$4}\n           END{for(k in sum) printf \"%s mean=%.1fms max=%.1fms n=%d\\n\", k, sum[k]\/n[k], max[k], n[k]}'<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Attack the Right Layer<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Network wait:<\/strong> wrap every external call in a 2 s timeout and a 60 s cache. A hung API must never hold a worker for 30 s.<\/li>\n<li><strong>Database latency:<\/strong> fix the query or the buffer pool. Adding FPM workers while the DB is saturated simply moves the queue.<\/li>\n<li><strong>Disk\/opcache:<\/strong> verify <code>opcache.enable=1<\/code> and <code>opcache.validate_timestamps=0<\/code> in production, with a deploy hook to reload FPM.<\/li>\n<li><strong>Lock contention:<\/strong> move sessions to Redis. File-based sessions serialise on the same inode and are a classic hidden stall.<\/li>\n<li><strong>Genuine CPU:<\/strong> this is the only case where a larger instance or a faster core actually helps. Our <a href=\"https:\/\/virtualserversvps.com\/\">VPS configuration and sizing pages<\/a> cover what each tier delivers under sustained load.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">One caution on profiling overhead: an always-on APM agent can add 5&ndash;15 percent CPU. On a single-core VPS that is real money. Start with the FPM slow log, escalate to <code>strace<\/code> for a single PID, and only install an agent once you have proven which class of bottleneck you are chasing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The One-Line Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Idle CPU plus a slow page almost always means waiting, not computing. Measure what the process is waiting on before you change a single setting &mdash; and revisit the <a href=\"https:\/\/virtualserversvps.com\/blog\/tuning-php-fpm-process-pools-by-workload\">PHP-FPM pool sizing rules<\/a> only after the wait is eliminated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When a page takes 1.8 seconds and CPU sits at 40 percent, the problem is not capacity &mdash; it is latency somewhere in the request path. Guessing at it means&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1179","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing\" \/>\n<meta property=\"og:description\" content=\"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-19T22:01:59+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/\",\"name\":\"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-09-19T22:01:59+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/","og_locale":"en_US","og_type":"article","og_title":"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing","og_description":"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing","og_url":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-09-19T22:01:59+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/","url":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/","name":"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-09-19T22:01:59+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/profiling-php-fpm-slowlog-strace-bottlenecks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Profiling PHP-FPM Bottlenecks on a VPS: slowlog, strace, and Real Request Tracing"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1179"}],"version-history":[{"count":0,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1179\/revisions"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}