Skip to content

Stuck lsphp processes and high CPU on cPanel: how to fix

If top or the WHM Process Manager shows lsphp processes piling up, burning CPU or never exiting, you can sort the healthy ones from the stuck ones in a few minutes. Find what each stuck process is waiting on, stop it without taking other sites down, and set a time limit so LiteSpeed clears the next one for you.

You opened top or the WHM Process Manager and found a long column of lsphp processes, some near 100% CPU and some hours old. This page shows you which ones are a problem and how to stop them safely. lsphp is PHP itself, built to talk to LiteSpeed Web Server over LSAPI (LiteSpeed Server Application Programming Interface), so every PHP page on a LiteSpeed server runs inside one of these processes. Seeing many of them is normal. The warning sign is a process busy on one script for more than a few minutes, because it holds a slot and memory that new visitors need. The fix is to find what the stuck processes wait on, end only those, and set LSAPI_MAX_PROCESS_TIME so LiteSpeed ends the next runaway for you.

What you’ll accomplish

  • Tell the lsphp parent, idle children and stuck children apart in one listing.
  • Find out whether a stuck process is looping on CPU or waiting on a database, a remote API or a lock.
  • Stop the stuck processes for one account without restarting PHP for every site on the server.
  • Set a wall-clock limit so LiteSpeed kills runaway requests on its own.
  • Prove the pile-up is gone and stays gone at the next busy hour.

Prerequisites

  • Root SSH access to a cPanel/WHM server running LiteSpeed Web Server Enterprise with the LiteSpeed WHM plugin. Version 6.x of LiteSpeed is assumed. Notes for OpenLiteSpeed, the free open-source edition, appear where it behaves differently.
  • PHP served through LSAPI, which is the LiteSpeed default on cPanel. EasyApache 4 installs the binaries at paths such as /opt/cpanel/ea-php82/root/usr/bin/lsphp. If your sites run on PHP-FPM instead, read “When this is the wrong approach” first.
  • strace installed, a tool that shows the system calls a process is making. On AlmaLinux or Rocky Linux, dnf install strace adds it.
  • Access to the LiteSpeed WebAdmin console, opened from WHM under Plugins, then LiteSpeed Web Server.

How it works

LiteSpeed runs PHP in a mode it calls ProcessGroup, the default on cPanel. For each account and PHP version, it starts one lsphp parent process that runs as that account’s user. The parent forks children, which are copies of itself that handle the actual requests. Children share the parent’s opcode cache, the memory where PHP keeps compiled scripts.

A child shows its state in its command line. A busy child is renamed to lsphp: followed by the script it is running, for example lsphp:/home/bakery/public_html/index.php. Long paths are cut to their last 45 characters, so the start of a deep path may be missing. An idle child shows plain lsphp. Idle children exit after LSAPI_MAX_IDLE seconds (300 by default), and every child retires after LSAPI_MAX_REQS requests (10,000 by default). A healthy tree therefore keeps changing, and a busy child moves on to a new script within seconds.

A stuck child is one whose request never finishes. It shows the same script path every time you look, and it either burns CPU nonstop or sits waiting. The parent does have a safety net, LSAPI_MAX_PROCESS_TIME, which kills any child that spends too long on one request. LiteSpeed documents its default as 3,600 seconds, so a stuck child can hold its slot for a full hour before anything ends it.

Example ps output for one cPanel account: the long-lived lsphp parent, one child in R state at 98.7% CPU for 22 minutes on wp-cron.php, two children in S state near 0% CPU for 21 minutes on index.php, and healthy children that are idle or only seconds old

Each account can only run so many children at once. On cPanel that cap is PHP suEXEC Max Conn, a LiteSpeed server setting with a default of 10 per LiteSpeed worker process. When stuck children fill it, new visitors to that site wait in a queue and then get a 503 error, while other accounts keep working.

Step-by-step

  1. Confirm LiteSpeed is the web server. Everything below assumes LiteSpeed is handing requests to lsphp:

    /usr/local/lsws/bin/lswsctrl status

    Example output:

    litespeed is running with PID 2214.

    If it reports litespeed is not running or the file does not exist, Apache is serving. lsphp processes on an Apache server come from CloudLinux’s mod_lsapi module, which has its own settings, so this page only applies in part.

  2. Count lsphp processes per account. This shows which account to look at first:

    ps -C lsphp -o user= | sort | uniq -c | sort -rn | head -5

    Example output:

          6 bakery
          4 tlshop
          2 jfcafe

    Each account’s count includes its parent, so subtract one. Start with the account at the top, or with the account whose site is slow. If every account shows a similar count, real traffic is the more likely story than one stuck site.

  3. Draw that account’s process tree. etimes is the elapsed time in seconds, stat is the process state, and --forest draws children under their parent:

    ps -u bakery -o pid,etimes,stat,pcpu,args --forest

    Example output:

        PID ELAPSED STAT %CPU COMMAND
      48120   86410 S     0.0 lsphp
      51877    1342 R    98.7  \_ lsphp:/home/bakery/public_html/wp-cron.php
      51903    1290 S     0.1  \_ lsphp:/home/bakery/public_html/index.php
      51911    1287 S     0.1  \_ lsphp:/home/bakery/public_html/index.php
      52640      41 S     0.0  \_ lsphp
      52702       3 S     2.1  \_ lsphp:/home/bakery/public_html/index.php

    Read it in this order. The top lsphp with a large elapsed time is the parent, and it should stay. Its command may show the full binary path on some builds. ELAPSED is the age of each process, not of its current request, and %CPU is an average over that whole life. PID 51877 is in state R (running) and has averaged 98.7% CPU for 22 minutes, which points to a loop in the PHP code. PIDs 51903 and 51911 are in state S (sleeping) with almost no CPU, so they may be waiting for something outside PHP. The last two are healthy. A D state means the process is waiting on the disk.

    Run the same command again a minute later. A child that still shows the same PID and the same script is your suspect. On a busy site, a healthy child can live for many minutes while serving thousands of short requests. The second look and step 4 confirm it is stuck.

  4. Find out what a waiting child is waiting on. Attach strace for ten seconds, then list the network connections the same process holds:

    timeout 10 strace -p 51903
    ss -tnp | grep 'pid=51903,'

    Example output:

    strace: Process 51903 attached
    poll([{fd=9, events=POLLIN}], 1, 1000) = 0 (Timeout)
    poll([{fd=9, events=POLLIN}], 1, 1000) = 0 (Timeout)
    strace: Process 51903 detached
    ESTAB 0      0      203.0.113.25:50412 198.51.100.40:443 users:(("lsphp",pid=51903,fd=9))

    Repeated poll or read calls that end in a timeout mean the process is waiting for an answer. The ss line shows who it is waiting for. A remote address on port 443 is an outside HTTPS service, such as a payment gateway, a licence server or an API. A peer on port 3306 is the database. If ss prints nothing and strace shows one call that never returns, the wait is usually on the local database through its Unix socket, so go to step 5. A flock call points to a file lock, often a PHP session file held by another request from the same visitor.

  5. Check the database for slow queries. If the child is waiting on MySQL or MariaDB, a long query will show here:

    mysql -e "SELECT ID, USER, TIME, STATE, LEFT(INFO,60) AS query FROM information_schema.PROCESSLIST WHERE COMMAND='Query' AND TIME > 30 ORDER BY TIME DESC;"

    Example output:

    +-------+------------+------+--------------+--------------------------------------------------------------+
    | ID    | USER       | TIME | STATE        | query                                                        |
    +-------+------------+------+--------------+--------------------------------------------------------------+
    | 90412 | bakery_wp1 | 1281 | Sending data | SELECT option_name, option_value FROM wp_options WHERE autol |
    +-------+------------+------+--------------+--------------------------------------------------------------+

    A query from the same account’s database user that has run for many minutes is almost certainly what the child is stuck on. Ending queries safely is covered in detecting and killing long-running queries. An empty result rules the database out.

  6. Read what LiteSpeed’s PHP has already logged. Messages from lsphp go to stderr.log, which sits in /usr/local/lsws/logs/ or /var/log/apache2/ depending on the setup:

    grep -ohE '(Force killing|Killing) runaway process PID: [0-9]+|Reached max children process limit: .*LSAPI_CHILDREN' /usr/local/lsws/logs/stderr.log /var/log/apache2/stderr.log 2>/dev/null | tail -5

    Example output:

    Reached max children process limit: 10, extra: 3, current: 13, busy: 13, please increase LSAPI_CHILDREN
    Reached max children process limit: 10, extra: 3, current: 13, busy: 13, please increase LSAPI_CHILDREN

    This line means an account used every child it is allowed, including three spare ones. It may date from earlier in the incident, when more children were stuck. Notice the advice at the end. When children are stuck, raising the limit only gives the problem more slots to fill, so leave it alone for now. Killing runaway process lines mean LSAPI_MAX_PROCESS_TIME has already been ending requests.

  7. Stop the stuck children, and only those. Send each one a normal stop signal. The parent stays up and forks fresh children as visitors arrive:

    kill 51877 51903 51911
    ps -u bakery -o pid,etimes,stat,pcpu,args --forest

    Example output:

        PID ELAPSED STAT %CPU COMMAND
      48120   86460 S     0.0 lsphp
      52640      91 S     0.0  \_ lsphp
      52981       2 S     1.8  \_ lsphp:/home/bakery/public_html/index.php

    If a PID is still listed after a few seconds, repeat with kill -9 for that PID. If the whole tree is misbehaving, restart PHP for this account only with touch /home/bakery/.lsphp_restart.txt. Avoid killall lsphp on a shared server, because it cuts off every account’s requests in progress.

  8. Set a wall-clock limit for any single request. On Linux, PHP’s own max_execution_time does not count time spent waiting on the network or the database. That is why it never stops the waiting children from step 4. LSAPI_MAX_PROCESS_TIME counts real elapsed time. In the WebAdmin console, go to Configuration, then Server, then PHP. Under PHP Handler Defaults, keep the existing lines in the Environment box and add this one:

    LSAPI_MAX_PROCESS_TIME=300

    Save, then apply it with a graceful restart from the console. Running PHP parents keep their old settings, so finish with Actions, then Restart Detached PHP Processes. From the shell, touch /usr/local/lsws/admin/tmp/.lsphp_restart.txt does the same. Five minutes is generous for a web page. If one site runs a legitimate long import, give only that site a higher value with an LS_EXTAPP_ENV LSAPI_MAX_PROCESS_TIME=1800 line, wrapped in an <IfModule LiteSpeed> block, in its include file under /etc/apache2/conf.d/userdata/. On OpenLiteSpeed, the same line goes in the Environment field of the lsphp External App, and killall lsphp restarts PHP.

  9. Remove the cause you found in steps 3 to 6. The limit is only a safety net:

    • A loop on CPU (state R). The script in the command line is your lead. For wp-cron.php, a plugin’s scheduled job is looping. Find it in the site’s PHP error_log, then update or disable that plugin. To keep cron from running inside visitor requests, add define('DISABLE_WP_CRON', true); to wp-config.php and run wp-cron.php from a real cron job every five minutes.
    • A slow remote service (port 443 in step 4). The code is calling an outside service with no short timeout. Set a connect and response timeout of 10 to 15 seconds in that plugin’s or app’s settings. For PHP’s own stream functions, default_socket_timeout (60 seconds by default) sets the ceiling, and you can change it in the editor mode of the MultiPHP INI Editor. It does not apply to cURL, which has its own options.
    • The database (step 5). Fix or index the slow query. The PHP children stop piling up once the query returns quickly.
    • A session lock. Requests from the same visitor queue behind each other’s session file. The usual fix is in the application, by closing the session as soon as it is no longer written.

Validate it works

First, take two snapshots of every busy child on the server, one minute apart, and keep the lines that appear in both:

ps -C lsphp -o pid=,args= | grep 'lsphp:' | sort > /root/lsphp-a.txt
sleep 60
ps -C lsphp -o pid=,args= | grep 'lsphp:' | sort > /root/lsphp-b.txt
comm -12 /root/lsphp-a.txt /root/lsphp-b.txt

No output means no child stayed on the same script for a full minute. A line in the result is a candidate, not a verdict, so check it with steps 4 and 5. Repeat the check during your busiest hour, because a quiet hour after a restart proves little.

Next, confirm a running parent picked up the new limit. Use the parent PID from step 3, or the new one if it restarted:

tr '\0' '\n' < /proc/48120/environ | grep LSAPI_MAX_PROCESS_TIME

Example output:

LSAPI_MAX_PROCESS_TIME=300

If nothing prints, that parent started before your change. Restart detached PHP again, as in step 8.

Finally, check the site from outside the server:

curl -sS -o /dev/null -w '%{http_code} %{time_total}\n' https://bakery.example/

Example output:

200 0.412

A 200 with a time under a second or two means visitors are getting a free child again. A 503 means the account is still out of children, so go back to step 3.

Troubleshooting

  • The stuck children come back within minutes. The cause is still there, often a cron job or a page every visitor loads. Repeat steps 3 and 4 on the new PIDs. The same script path every time tells you where the problem lives.
  • Visitors see 508 Resource Limit Is Reached on CloudLinux. CloudLinux runs each account in an LVE (Lightweight Virtual Environment), a container with its own limits on entry processes, process count, CPU and memory. Stuck children count against those limits. Run lvetop to watch accounts live, and lveinfo --period=1d --by-fault=any --display-username to see who hit a limit today. The limits themselves are explained in CloudLinux LVE limits explained.
  • The new limit seems to be ignored. The detached parent still holds its old environment. Restart detached PHP, then repeat the environ check above. Also search the domain’s include files under /etc/apache2/conf.d/userdata/ for an LS_EXTAPP_ENV line, which sets the same variable for one site.
  • An lsphp process uses a lot of CPU but has no script path and a strange owner. Check the binary it really runs with ls -l /proc/<pid>/exe. A real one points to /opt/cpanel/ea-phpXX/root/usr/bin/lsphp or a path under /usr/local/lsws/. A path under /tmp, /dev/shm or a home directory is malware using a familiar name, and that is a security incident.

When this is the wrong approach

If ps -C lsphp shows nothing and you see php-fpm processes, your sites run on PHP-FPM, and the timeout to use is request_terminate_timeout in the pool. If many children are busy but none stays on the same script for a minute, nothing is stuck. That is real traffic, and the answer is page caching or more capacity, not killing processes. To change which handler an account uses, or to size LSAPI_CHILDREN deliberately, see what LSPHP is and how to switch the PHP handler on cPanel. Every variable used here is listed in LiteSpeed’s LSPHP options reference.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.