Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Why Is PHP Slow on the Command Line? How to Speed It Up

Sometimes PHP scripts run slowly when you start them from the terminal. This guide helps you find the cause and fix it. You need root or SSH access.

Dedicated Servers2 min read7 steps

What is PHP CLI?

PHP is the language many websites use. CLI means command line interface. It is the text window where you type commands instead of clicking. PHP CLI runs scripts in that window, such as cron jobs or tools like Composer.

Steps to find the problem

  1. Log in to your server over SSH.
  2. Time a simple PHP start with this command.
time php -v

This shows how long PHP takes just to start. It should finish in a fraction of a second. If it takes several seconds, PHP loads too much.

  1. List the loaded extensions. Extensions are add-ons that give PHP more features.
php -m

This prints every add-on that PHP loads.

  1. Find which settings files PHP reads.
php --ini

This shows the path of php.ini and any extra files.

  1. Look for extensions you do not need, such as xdebug. Xdebug is a tool for developers and slows PHP a lot.
  2. Back up the settings file, then comment out the line with a semicolon. Example: ;zend_extension=xdebug.so.
  3. Run time php -v again to see the change.

Other common causes

  • Busy server. Run top to see if something eats the CPU or memory. The CPU is the brain of the server.
  • Slow disk. A disk that is busy or almost full makes everything slow.
  • Slow network lookups. If your script calls other websites, a bad DNS setting can add long waits. DNS turns names into numbers computers understand.
  • Memory limit too low. Check memory_limit in php.ini. Raise it if a script runs out of memory.
  • Opcache for CLI. Opcache saves compiled code. It is off for CLI by default, and that is normal for short scripts.
  • Wrong PHP version. Newer PHP versions are often faster. The version for CLI may differ from the one your website uses. Check with php -v.
Tip: Change only one thing at a time. Then you know which change helped.

Quick recap

  • PHP CLI runs PHP scripts from the terminal.
  • Use time php -v to measure the start time.
  • Disable extensions like xdebug that you do not need.
  • Check server load, disk space and DNS.
  • If it is still slow, ask Hostvento support to check your server.