<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Htop on Daniel Zhang</title><link>https://zhangdapeng.dev/tags/htop/</link><description>Recent content in Htop on Daniel Zhang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 03 Dec 2026 09:00:00 +0800</lastBuildDate><atom:link href="https://zhangdapeng.dev/tags/htop/index.xml" rel="self" type="application/rss+xml"/><item><title>Diagnosing High Memory Usage and Persistent Laravel Processes on Linux</title><link>https://zhangdapeng.dev/p/diagnosing-high-memory-usage-laravel-processes/</link><pubDate>Thu, 03 Dec 2026 09:00:00 +0800</pubDate><guid>https://zhangdapeng.dev/p/diagnosing-high-memory-usage-laravel-processes/</guid><description>&lt;img src="https://zhangdapeng.dev/p/diagnosing-high-memory-usage-laravel-processes/cover.png" alt="Featured image of post Diagnosing High Memory Usage and Persistent Laravel Processes on Linux" /&gt;&lt;h1 id="diagnosing-high-memory-usage-and-persistent-laravel-processes-on-linux"&gt;Diagnosing High Memory Usage and Persistent Laravel Processes on Linux
&lt;/h1&gt;&lt;p&gt;When managing a Linux server running Docker, PHP-FPM, and Laravel applications, you may occasionally notice that memory usage keeps increasing or that multiple PHP processes remain running for an unexpectedly long time.&lt;/p&gt;
&lt;p&gt;Some common examples include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Multiple &lt;code&gt;dockerd&lt;/code&gt; entries appearing in &lt;code&gt;htop&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Several PHP-FPM workers consuming significant memory.&lt;/li&gt;
&lt;li&gt;Multiple &lt;code&gt;php artisan schedule:run&lt;/code&gt; processes accumulating.&lt;/li&gt;
&lt;li&gt;Laravel queue workers remaining alive even when there are no pending jobs.&lt;/li&gt;
&lt;li&gt;Processes continuing to run after their expected tasks have finished.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding how Linux processes work and how Laravel manages background tasks is essential for diagnosing these problems.&lt;/p&gt;
&lt;p&gt;This article summarizes a practical troubleshooting process and explains how to identify and manage these processes.&lt;/p&gt;
&lt;h2 id="1-understanding-multiple-docker-processes-in-htop"&gt;1. Understanding Multiple Docker Processes in htop
&lt;/h2&gt;&lt;p&gt;You may encounter output similar to this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;19249 root 20 0 2019M 63340 5364 S 0.0 0.8 dockerd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;19250 root 20 0 2019M 63340 5364 S 0.0 0.8 dockerd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;19251 root 20 0 2019M 63340 5364 S 0.0 0.8 dockerd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;19252 root 20 0 2019M 63340 5364 S 0.0 0.8 dockerd
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;At first glance, it looks like multiple Docker daemon processes are consuming memory.&lt;/p&gt;
&lt;p&gt;However, these entries may actually represent threads belonging to the same &lt;code&gt;dockerd&lt;/code&gt; process.&lt;/p&gt;
&lt;p&gt;Docker is written in Go, and its runtime creates multiple operating system threads to handle concurrent operations.&lt;/p&gt;
&lt;h3 id="understanding-the-memory-values"&gt;Understanding the memory values
&lt;/h3&gt;&lt;p&gt;Two important columns in &lt;code&gt;htop&lt;/code&gt; are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;VIRT&lt;/strong&gt;: Total virtual memory allocated or mapped by the process.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RES&lt;/strong&gt;: Resident memory currently occupying physical RAM.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;VIRT: 2019M
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;RES: 63340 KB
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This means the process has approximately 2 GB of virtual address space, but only around 62 MB of resident physical memory.&lt;/p&gt;
&lt;p&gt;The virtual memory value does not mean that the process is consuming 2 GB of physical RAM.&lt;/p&gt;
&lt;p&gt;Also, multiple thread entries share the same process address space. Their RES values must not be added together as if they were independent processes.&lt;/p&gt;
&lt;h3 id="how-to-hide-thread-entries"&gt;How to hide thread entries
&lt;/h3&gt;&lt;p&gt;In &lt;code&gt;htop&lt;/code&gt;, press:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;H
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This toggles the display of user threads.&lt;/p&gt;
&lt;p&gt;In &lt;code&gt;top&lt;/code&gt;, you can also press uppercase &lt;code&gt;H&lt;/code&gt; to toggle thread visibility.&lt;/p&gt;
&lt;p&gt;This makes it easier to distinguish actual processes from their threads.&lt;/p&gt;
&lt;h2 id="2-identifying-php-fpm-memory-consumption"&gt;2. Identifying PHP-FPM Memory Consumption
&lt;/h2&gt;&lt;p&gt;Another common situation is seeing multiple PHP-FPM workers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;827 nobody 20 0 3879M 61316 1088 S 0.0 0.8 php-fpm: pool www
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;826 nobody 20 0 3879M 59820 1096 S 0.0 0.8 php-fpm: pool www
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;834 nobody 20 0 3878M 59312 1132 S 0.0 0.8 php-fpm: pool www
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;836 nobody 20 0 3878M 59208 1068 S 0.0 0.8 php-fpm: pool www
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Unlike Docker threads, PHP-FPM workers are independent processes.&lt;/p&gt;
&lt;p&gt;Each worker has its own process memory, although some memory regions, such as shared libraries and OPcache, may be shared.&lt;/p&gt;
&lt;h3 id="why-does-php-fpm-use-so-much-memory"&gt;Why does PHP-FPM use so much memory?
&lt;/h3&gt;&lt;p&gt;There are several possible reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;PHP scripts process large arrays or datasets.&lt;/li&gt;
&lt;li&gt;ORM queries load large amounts of database records.&lt;/li&gt;
&lt;li&gt;Export or report-generation tasks require significant memory.&lt;/li&gt;
&lt;li&gt;PHP extensions allocate additional memory.&lt;/li&gt;
&lt;li&gt;Long-running workers retain memory after processing requests.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;PHP&amp;rsquo;s memory manager may retain allocated memory for reuse instead of immediately returning it to the operating system.&lt;/p&gt;
&lt;p&gt;Consequently, a worker&amp;rsquo;s resident memory may remain relatively high even after a request has completed.&lt;/p&gt;
&lt;h3 id="how-to-prevent-excessive-memory-accumulation"&gt;How to prevent excessive memory accumulation
&lt;/h3&gt;&lt;p&gt;PHP-FPM provides several configuration options.&lt;/p&gt;
&lt;p&gt;Open the relevant pool configuration file, usually &lt;code&gt;www.conf&lt;/code&gt;, and check the following settings:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;pm.max_requests&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;500&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This setting instructs each worker to handle a maximum of 500 requests before exiting. PHP-FPM then creates a replacement worker.&lt;/p&gt;
&lt;p&gt;It is useful for limiting long-term memory accumulation.&lt;/p&gt;
&lt;p&gt;If you are using dynamic process management, you can also adjust:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;pm.max_spare_servers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This limits the number of idle workers retained by PHP-FPM.&lt;/p&gt;
&lt;p&gt;The appropriate values depend on your server&amp;rsquo;s available memory and application traffic.&lt;/p&gt;
&lt;p&gt;One important detail: when evaluating total PHP-FPM memory usage, remember that RSS includes shared memory. Adding every worker&amp;rsquo;s RSS together can overestimate actual physical memory consumption. PSS is more useful for estimating each process&amp;rsquo;s proportional share.&lt;/p&gt;
&lt;h2 id="3-determining-whether-a-process-runs-inside-docker"&gt;3. Determining Whether a Process Runs Inside Docker
&lt;/h2&gt;&lt;p&gt;When you find an unexpected PHP process, the next step is determining whether it belongs to the host system or a Docker container.&lt;/p&gt;
&lt;p&gt;For example, suppose you want to investigate PID &lt;code&gt;827&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Run:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cat /proc/827/cgroup
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="host-process-example"&gt;Host process example
&lt;/h3&gt;&lt;p&gt;You might see:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;11:devices:/system.slice/php-fpm.service
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;10:blkio:/system.slice/php-fpm.service
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;8:memory:/system.slice/php-fpm.service
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;/system.slice/php-fpm.service&lt;/code&gt; path indicates that the process belongs to a systemd-managed service on the host.&lt;/p&gt;
&lt;h3 id="docker-container-process-example"&gt;Docker container process example
&lt;/h3&gt;&lt;p&gt;A Docker-managed process may show:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;11:devices:/docker/01aa6624de46bdf2a927da508c8c9e29...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;10:blkio:/docker/01aa6624de46bdf2a927da508c8c9e29...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;8:memory:/docker/01aa6624de46bdf2a927da508c8c9e29...
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;/docker/&lt;/code&gt; path and container ID indicate that the process belongs to a Docker container.&lt;/p&gt;
&lt;p&gt;The exact cgroup layout can vary depending on the cgroup version and container runtime.&lt;/p&gt;
&lt;h3 id="find-the-corresponding-docker-container"&gt;Find the corresponding Docker container
&lt;/h3&gt;&lt;p&gt;Once you have identified the container ID, use:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;docker ps --filter &lt;span class="s2"&gt;&amp;#34;id=01aa6624de46&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To include stopped containers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;docker ps -a --filter &lt;span class="s2"&gt;&amp;#34;id=01aa6624de46&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also inspect the process hierarchy:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pstree -sp &lt;span class="m"&gt;827&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A process hierarchy containing &lt;code&gt;containerd-shim&lt;/code&gt; can provide additional evidence that the process belongs to a container.&lt;/p&gt;
&lt;h2 id="4-investigating-accumulated-laravel-schedulerun-processes"&gt;4. Investigating Accumulated Laravel schedule:run Processes
&lt;/h2&gt;&lt;p&gt;One particularly interesting problem occurs when multiple Laravel scheduler processes accumulate.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;18740 root 20 0 138M 46976 15264 S 0.0 0.6 php artisan schedule:run
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;19186 root 20 0 138M 46976 15264 S 0.0 0.6 php artisan schedule:run
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;22054 root 20 0 138M 46976 15264 S 0.0 0.6 php artisan schedule:run
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;22806 root 20 0 138M 46976 15264 S 0.0 0.6 php artisan schedule:run
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Why are there so many instances of the same command?&lt;/p&gt;
&lt;h3 id="how-laravels-scheduler-works"&gt;How Laravel&amp;rsquo;s scheduler works
&lt;/h3&gt;&lt;p&gt;A typical Laravel scheduler is triggered through Cron:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-cron" data-lang="cron"&gt;* * * * * cd /path/to/project &amp;amp;&amp;amp; php artisan schedule:run &amp;gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Cron starts a new &lt;code&gt;schedule:run&lt;/code&gt; process every minute.&lt;/p&gt;
&lt;p&gt;Under normal circumstances, each process checks the scheduled tasks, executes the tasks that are due, and exits.&lt;/p&gt;
&lt;p&gt;However, if a scheduled task takes longer than expected or becomes blocked, the previous scheduler process may still be running when Cron starts the next one.&lt;/p&gt;
&lt;p&gt;This can result in multiple processes accumulating.&lt;/p&gt;
&lt;h3 id="identify-how-long-the-processes-have-been-running"&gt;Identify how long the processes have been running
&lt;/h3&gt;&lt;p&gt;Use:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ps -eo pid,lstart,etime,cmd &lt;span class="p"&gt;|&lt;/span&gt; grep &lt;span class="s2"&gt;&amp;#34;schedule:run&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;18740 Wed Dec 2 01:10:01 2026 46:12 php artisan schedule:run
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;etime&lt;/code&gt; column shows the elapsed time since the process started.&lt;/p&gt;
&lt;p&gt;This is much more useful than the &lt;code&gt;TIME+&lt;/code&gt; column in &lt;code&gt;htop&lt;/code&gt;, which displays accumulated CPU time rather than total process lifetime.&lt;/p&gt;
&lt;h3 id="why-does-withoutoverlapping-not-always-solve-the-problem"&gt;Why does withoutOverlapping() not always solve the problem?
&lt;/h3&gt;&lt;p&gt;Laravel provides:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;$schedule&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;your:command&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;everyMinute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;withoutOverlapping&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This prevents the same scheduled task from running concurrently by using a cache-based mutex.&lt;/p&gt;
&lt;p&gt;However, it does not prevent Cron from launching another &lt;code&gt;schedule:run&lt;/code&gt; process every minute.&lt;/p&gt;
&lt;p&gt;If a scheduler process is blocked during application initialization, cache access, database access, or another operation, new scheduler processes may still accumulate.&lt;/p&gt;
&lt;p&gt;It is important to distinguish between preventing scheduled task overlap and preventing scheduler process accumulation.&lt;/p&gt;
&lt;h3 id="investigate-the-actual-blocking-point"&gt;Investigate the actual blocking point
&lt;/h3&gt;&lt;p&gt;Run the scheduler manually with verbose output:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan schedule:run -vvv
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Check the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Whether the scheduler can initialize successfully.&lt;/li&gt;
&lt;li&gt;Whether it gets stuck while connecting to Redis or the database.&lt;/li&gt;
&lt;li&gt;Whether a particular scheduled command takes too long.&lt;/li&gt;
&lt;li&gt;Whether another application service provider is blocking initialization.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also inspect running Artisan processes:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ps aux &lt;span class="p"&gt;|&lt;/span&gt; grep artisan
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="use-flock-to-prevent-overlapping-scheduler-processes"&gt;Use flock to prevent overlapping scheduler processes
&lt;/h3&gt;&lt;p&gt;One additional protection is using Linux &lt;code&gt;flock&lt;/code&gt; directly in Cron:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-cron" data-lang="cron"&gt;* * * * * /usr/bin/flock -xn /tmp/laravel-schedule.lock -c &amp;#34;cd /path/to/project &amp;amp;&amp;amp; php artisan schedule:run &amp;gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This ensures that only one scheduler invocation can hold the lock at a time.&lt;/p&gt;
&lt;p&gt;If the previous invocation is still running, the next Cron execution exits without starting another scheduler process.&lt;/p&gt;
&lt;p&gt;This is particularly useful when scheduled tasks occasionally take longer than one minute.&lt;/p&gt;
&lt;p&gt;Note that &lt;code&gt;runInBackground()&lt;/code&gt; can also be useful for independent, long-running scheduled commands, but it should not be used as a substitute for proper process supervision.&lt;/p&gt;
&lt;h2 id="5-understanding-laravel-queue-workers"&gt;5. Understanding Laravel Queue Workers
&lt;/h2&gt;&lt;p&gt;Another process that often appears in server monitoring tools is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --queue&lt;span class="o"&gt;=&lt;/span&gt;update-vip-service &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --sleep&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --tries&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --daemon
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Unlike &lt;code&gt;schedule:run&lt;/code&gt;, this process is designed to remain alive.&lt;/p&gt;
&lt;h3 id="why-does-queuework-keep-running"&gt;Why does queue:work keep running?
&lt;/h3&gt;&lt;p&gt;Laravel queue workers are long-running processes.&lt;/p&gt;
&lt;p&gt;Their basic workflow is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Bootstrap the Laravel application.&lt;/li&gt;
&lt;li&gt;Connect to the configured queue backend.&lt;/li&gt;
&lt;li&gt;Retrieve available jobs.&lt;/li&gt;
&lt;li&gt;Execute a job.&lt;/li&gt;
&lt;li&gt;If the queue is empty, wait for the configured sleep interval.&lt;/li&gt;
&lt;li&gt;Continue polling for new jobs.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;--sleep&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;means the worker waits approximately three seconds when no jobs are available before checking again.&lt;/p&gt;
&lt;p&gt;Therefore, seeing a queue worker in the &lt;code&gt;S&lt;/code&gt; (Sleeping) state with almost zero CPU usage is generally normal.&lt;/p&gt;
&lt;p&gt;It does not necessarily indicate a stuck process.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;--daemon&lt;/code&gt; option was historically used to explicitly enable long-running worker behavior. In modern Laravel versions, &lt;code&gt;queue:work&lt;/code&gt; already operates as a long-running worker, so explicitly specifying &lt;code&gt;--daemon&lt;/code&gt; is generally unnecessary.&lt;/p&gt;
&lt;h3 id="how-to-stop-a-queue-worker-safely"&gt;How to stop a queue worker safely
&lt;/h3&gt;&lt;p&gt;If you need to stop a specific worker, you have several options.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Option 1: Send SIGTERM&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;kill&lt;/span&gt; &lt;span class="m"&gt;6573&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This requests a graceful shutdown. Laravel can finish the current job before exiting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Option 2: Restart Laravel queue workers&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;From the application directory:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:restart
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This signals workers to exit after completing their current jobs.&lt;/p&gt;
&lt;p&gt;This is particularly useful after deploying new application code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Option 3: Forcefully terminate a process&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If a worker is genuinely unresponsive:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;kill&lt;/span&gt; -9 &lt;span class="m"&gt;6573&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For multiple workers belonging to a specific queue, first inspect the matching processes:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pgrep -af &lt;span class="s2"&gt;&amp;#34;queue=update-vip-service&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Only after confirming the matches should you consider terminating them.&lt;/p&gt;
&lt;p&gt;Be careful with &lt;code&gt;SIGKILL&lt;/code&gt;: it does not allow Laravel to perform graceful shutdown operations. An interrupted job may need to be retried or recovered according to the queue driver&amp;rsquo;s reservation and retry configuration.&lt;/p&gt;
&lt;h3 id="why-does-a-queue-worker-sometimes-remain-stuck"&gt;Why does a queue worker sometimes remain stuck?
&lt;/h3&gt;&lt;p&gt;A long-running worker can encounter problems such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Database connection failures.&lt;/li&gt;
&lt;li&gt;Redis connection problems.&lt;/li&gt;
&lt;li&gt;Slow external API requests.&lt;/li&gt;
&lt;li&gt;Database lock contention.&lt;/li&gt;
&lt;li&gt;Jobs that take longer than expected.&lt;/li&gt;
&lt;li&gt;Missing timeout configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, if a worker is waiting indefinitely for a database or external service, it may remain alive without processing new jobs.&lt;/p&gt;
&lt;p&gt;Consider configuring an appropriate timeout:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --queue&lt;span class="o"&gt;=&lt;/span&gt;update-vip-service &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --sleep&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --tries&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --timeout&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;60&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The timeout should be coordinated with the queue connection&amp;rsquo;s &lt;code&gt;retry_after&lt;/code&gt; setting so that a job is not released for retry while the original worker is still executing it.&lt;/p&gt;
&lt;h2 id="6-managing-laravel-queue-workers-with-supervisor"&gt;6. Managing Laravel Queue Workers with Supervisor
&lt;/h2&gt;&lt;p&gt;If you are already using Supervisor, you generally do not need to manually manage queue worker processes.&lt;/p&gt;
&lt;p&gt;Supervisor is responsible for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Starting workers automatically.&lt;/li&gt;
&lt;li&gt;Restarting workers after unexpected exits.&lt;/li&gt;
&lt;li&gt;Keeping the configured number of workers running.&lt;/li&gt;
&lt;li&gt;Managing worker logs.&lt;/li&gt;
&lt;li&gt;Controlling worker processes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Laravel queue workers and Supervisor serve complementary purposes.&lt;/p&gt;
&lt;p&gt;Laravel workers continuously consume jobs, while Supervisor ensures that the workers remain available.&lt;/p&gt;
&lt;h3 id="why-use-supervisor-instead-of-cron"&gt;Why use Supervisor instead of Cron?
&lt;/h3&gt;&lt;p&gt;A queue worker is intended to be a long-running process.&lt;/p&gt;
&lt;p&gt;Putting the following command directly into Cron is not a good approach:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Cron is designed to execute scheduled commands, not continuously supervise background workers.&lt;/p&gt;
&lt;p&gt;Supervisor is a better choice because it monitors process health and automatically restarts workers when necessary.&lt;/p&gt;
&lt;h3 id="example-supervisor-configuration"&gt;Example Supervisor configuration
&lt;/h3&gt;&lt;p&gt;Create a configuration file:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;/etc/supervisor/conf.d/laravel-vip-worker.conf
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;[program:laravel-vip-worker]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;process_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;%(program_name)s_%(process_num)02d&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;php /var/www/html/artisan queue:work --queue=update-vip-service --sleep=3 --tries=3 --timeout=60 --max-jobs=1000 --memory=128&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;autostart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;autorestart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;nobody&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;numprocs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;redirect_stderr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;stdout_logfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/var/log/supervisor/vip-worker.log&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Important settings:&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Setting&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;autostart&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Automatically start workers when Supervisor starts.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;autorestart&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Restart workers when they exit unexpectedly or normally.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;user&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;User account used to execute the worker.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;numprocs&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Number of worker processes to start.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;--timeout=60&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Maximum execution time for an individual job.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;--max-jobs=1000&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Restart the worker after processing 1,000 jobs.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;--memory=128&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Restart the worker when its memory usage exceeds the configured threshold.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;After updating the configuration:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;supervisorctl reread
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;supervisorctl update
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Check the worker status:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;supervisorctl status
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also restart a specific program:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;supervisorctl restart laravel-vip-worker:*
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Supervisor will start replacement workers when the previous ones exit.&lt;/p&gt;
&lt;h3 id="do-you-need-multiple-queue-workers"&gt;Do you need multiple queue workers?
&lt;/h3&gt;&lt;p&gt;Not necessarily.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;numprocs&lt;/code&gt; setting controls how many worker processes run simultaneously.&lt;/p&gt;
&lt;p&gt;A reasonable starting point depends on workload:&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Workload&lt;/th&gt;
					&lt;th style="text-align: right"&gt;Suggested workers&lt;/th&gt;
					&lt;th&gt;Considerations&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Low-frequency tasks&lt;/td&gt;
					&lt;td style="text-align: right"&gt;1–2&lt;/td&gt;
					&lt;td&gt;Usually sufficient for occasional jobs.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Moderate workloads&lt;/td&gt;
					&lt;td style="text-align: right"&gt;2–4&lt;/td&gt;
					&lt;td&gt;Provides additional concurrency.&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;High-frequency or slow I/O tasks&lt;/td&gt;
					&lt;td style="text-align: right"&gt;4–8&lt;/td&gt;
					&lt;td&gt;Allows more jobs to run concurrently.&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;These are starting points, not universal recommendations.&lt;/p&gt;
&lt;p&gt;Each worker consumes memory independently, although some memory regions may be shared.&lt;/p&gt;
&lt;p&gt;For a small server, running too many workers can waste RAM without providing meaningful performance improvements.&lt;/p&gt;
&lt;p&gt;Start with a small number of workers and increase it only when queue throughput or job latency justifies the additional resource consumption.&lt;/p&gt;
&lt;h2 id="7-a-real-world-root-cause-database-connection-failures"&gt;7. A Real-World Root Cause: Database Connection Failures
&lt;/h2&gt;&lt;p&gt;During the troubleshooting process described in this article, the underlying issue was eventually identified as a database connection failure.&lt;/p&gt;
&lt;p&gt;This explains why multiple Laravel processes could remain alive unexpectedly.&lt;/p&gt;
&lt;h3 id="how-database-failures-affect-schedulerun"&gt;How database failures affect schedule:run
&lt;/h3&gt;&lt;p&gt;Laravel scheduler initialization and scheduled tasks may need to access the database or cache.&lt;/p&gt;
&lt;p&gt;If the database is unavailable, these operations can block while waiting for connection attempts or network timeouts.&lt;/p&gt;
&lt;p&gt;Because Cron continues launching &lt;code&gt;schedule:run&lt;/code&gt; every minute, multiple scheduler processes may accumulate.&lt;/p&gt;
&lt;h3 id="how-database-failures-affect-queuework"&gt;How database failures affect queue:work
&lt;/h3&gt;&lt;p&gt;Queue workers may also depend on database connectivity.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A database-backed queue needs database access to retrieve jobs.&lt;/li&gt;
&lt;li&gt;A job may execute SQL queries.&lt;/li&gt;
&lt;li&gt;A job may call an external service and subsequently update database records.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When database connectivity fails, a long-running worker may become blocked or encounter repeated exceptions.&lt;/p&gt;
&lt;p&gt;The important distinction is that a queue worker normally remains alive by design. Its continued existence is not itself evidence of a problem.&lt;/p&gt;
&lt;p&gt;The actual problem is whether it can continue processing jobs successfully.&lt;/p&gt;
&lt;h3 id="recommended-checks"&gt;Recommended checks
&lt;/h3&gt;&lt;p&gt;When database connectivity is restored, inspect the relevant workers and scheduler processes.&lt;/p&gt;
&lt;p&gt;You can request a graceful restart of Laravel queue workers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:restart
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you use Supervisor, it will automatically start replacement workers when the old ones exit.&lt;/p&gt;
&lt;p&gt;Also inspect the database connection configuration and ensure that appropriate connection and query timeouts are configured for your environment.&lt;/p&gt;
&lt;p&gt;Do not assume that a single PDO timeout setting controls every possible database operation or network failure.&lt;/p&gt;
&lt;h2 id="8-useful-commands-for-daily-process-troubleshooting"&gt;8. Useful Commands for Daily Process Troubleshooting
&lt;/h2&gt;&lt;p&gt;The following commands are particularly useful when investigating Linux processes.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Purpose&lt;/th&gt;
					&lt;th&gt;Command&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Show processes and threads&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;htop&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Toggle thread visibility&lt;/td&gt;
					&lt;td&gt;Press &lt;code&gt;H&lt;/code&gt; in htop&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Show process start time and elapsed time&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;ps -eo pid,lstart,etime,cmd&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Inspect a process&amp;rsquo;s cgroup&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;cat /proc/PID/cgroup&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Show a process hierarchy&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;pstree -sp PID&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Display complete process commands&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;ps aux&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Find Laravel Artisan processes&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;pgrep -af artisan&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Find specific queue workers&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;pgrep -af queue:work&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;List Docker containers&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;docker ps&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Find a container by ID&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;docker ps --filter &amp;quot;id=CONTAINER_ID&amp;quot;&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Check Supervisor processes&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;supervisorctl status&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Restart Laravel queue workers&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;php artisan queue:restart&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Replace &lt;code&gt;PID&lt;/code&gt; and &lt;code&gt;CONTAINER_ID&lt;/code&gt; with the actual process ID and container ID.&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion
&lt;/h2&gt;&lt;p&gt;Investigating high memory usage on a Linux server requires understanding the difference between processes, threads, and long-running background workers.&lt;/p&gt;
&lt;p&gt;Several important lessons from this troubleshooting experience are worth remembering:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Multiple &lt;code&gt;dockerd&lt;/code&gt; entries may represent threads sharing one process memory space rather than independent Docker daemons.&lt;/li&gt;
&lt;li&gt;PHP-FPM workers are independent processes, but shared memory means their RSS values should not simply be added together.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/proc/PID/cgroup&lt;/code&gt; is a useful way to determine whether a process belongs to Docker or a host-level systemd service.&lt;/li&gt;
&lt;li&gt;Laravel&amp;rsquo;s &lt;code&gt;schedule:run&lt;/code&gt; should normally finish quickly. Accumulating instances often indicate blocked initialization or scheduled tasks that take too long.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;withoutOverlapping()&lt;/code&gt; prevents overlapping scheduled tasks, but does not prevent Cron from launching another scheduler process.&lt;/li&gt;
&lt;li&gt;Laravel queue workers are designed to run continuously. Their presence in &lt;code&gt;htop&lt;/code&gt; is normal when they are managed by Supervisor.&lt;/li&gt;
&lt;li&gt;Supervisor should manage the lifecycle and number of queue workers instead of relying on Cron to launch permanent background processes.&lt;/li&gt;
&lt;li&gt;Database connectivity problems can affect multiple background services simultaneously, making them appear to have unrelated process-management problems.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When troubleshooting server performance, do not immediately kill processes just because they consume memory or remain alive for a long time.&lt;/p&gt;
&lt;p&gt;First identify what they do, how they were started, whether they are managed by another service, and what they are waiting for.&lt;/p&gt;
&lt;p&gt;Understanding these details makes it much easier to identify the actual root cause and avoid introducing additional problems while fixing the original one.&lt;/p&gt;</description></item></channel></rss>