Bobcares

Top 3 reasons for php-cgi.exe high CPU usage and its fix

by | May 3, 2019

A slow server is always a nightmare for any server owner. And, when the slowness occurs due to applications like PHP, it adds fuel to the fire.

Unfortunately, any problem with PHP affects all PHP-based websites on the server. Therefore, a timely solution is always necessary.

That’s why, at Bobcares we often get requests from customers to fix php-cgi.exe high CPU usage in servers as part of our Server Administration Services.

Today, we’ll see the top reasons that cause high php-cgi.exe CPU usage and how our Support Engineers fix it.

 

Understanding php-cgi.exe

Often high load in Windows servers attributes to php-cgi.exe processes. Therefore, it’s worth to learn more on php-cgi.exe.

In simple words, php-cgi.exe is the executable for processing PHP requests on the server. This file is needed at the time of php configuration with web servers like IIS. The path to this binary depends on the folder at which PHP is installed on the server. By default, installation path will be at  C:\php\php-cgi.exe

Every time a user requests a website page via browser, it is this back-end php binary that show the results. Naturally, any problems with PHP binary will lead to higher resource usage on the server.

 

What causes php-cgi.exe high CPU usage?

From our experience in managing servers, our Support Engineers often deal with high CPU usage Windows servers. When checking the status of servers using Task Manager in Windows, in many cases, it will be the php-cgi.exe process that consumes 100% CPU.

Let’s now take a look on what causes the php-cgi.exe high resource usage.

 

1. Malformed PHP scripts

Unfortunately, high CPU usage by PHP happens due to bad scripts on some on the domains on the server. PHP demands couple of standards when developing any websites. When some developers call PHP functions in the wrong way, or put them in an infinite loop, the PHP process fails. These poorly coded scripts will call the php-cgi.exe PHP worker program on the server and will eat 100% of CPU.

Similarly, hackers often upload malicious PHP scripts that deliberately create high load on the server. Eventually, this would slow down the entire server and affect all the domains too.

 

2. Large number of PHP processes

Yet another reason for high CPU usage happens due to large number of PHP processes on the server.

In any server, there will be an ideal number of requests that PHP can process considering the physical memory capacity of the server. When there are more users beyond this capacity, each connection creates a new instance of php-cgi.exe

In other words, more users means more instances of php-cgi.exe. And all these processes take up considerable amount of server resources. It would take up all up all the available RAM. As a result, the CPU usage shoots up.

 

3. Problem in fetching content

PHP can cause high CPU usage when there are problems in fetching the desired result from the server. This particularly happens due to messed up permissions on some folders and lack of proper user privileges too.

Another scenario for PHP website problems arise when certain content fetching is done from a different server. In such cases, if there is a firewall or antivirus that is stops the content from arriving on the site, PHP permanently waits to finish loading the page. As a result, it would also cause high CPU usage.

 

How we fix high CPU usage by php-cgi.exe

We already saw the different reasons that would cause high CPU usage by PHP processes. Now, let’s see the typical measures that our Dedicated Engineers take to fix the resource usage on the server.

 

1. Identifying the problem user

In any case of high CPU usage on servers with many websites, the first step is to identify the exact user that runs the PHP script. Identifying this user helps to solve the problem immediately. That’s why, we open Task Manager in Windows, go to details tab, and then take a look at column “User name” for php-cgi.exe process that consumes 100% CPU.

Again, when it’s a Plesk Windows server, more details are available from the Plesk Panel. In Plesk ->Tools&Settings-> Assistance and troubleshooting section we can see Process list screen. It shows information already according to domains. Our Support Engineers check the domain that consumes most CPU time. We then check the script and suggest customer to disable or modify it.

Also, if that happens to be a malicious script, we straightaway disable it and that would bring the server CPU usage back to normal.

 

2. Adjusting PHP settings

When the problem happens due to high number of users, we tweak the PHP settings on the server. For example, in older versions of IIS, we set the parameter maxInstances to 10 times the number of CPU processors on the server. That is your server has 4 CPU processors, this value would be 40. This helps to limit the amount of CGI processes that can be spinned up on the server. Thus, if there are more users beyond the server capacity, it will still keep the CPU usage under limits.

However, IIS 7.5 and higher handles the maxInstances dynamically by default. Therefore, our Support Engineers set the value as 0. This would equip the PHP FastCGI module capable of monitoring system state and adjust this number dynamically to give best possible performance.

A sample set of FastCGI parameters on a server we manage look like:

Again, for certain customers, we recommend customers to use a WAMP package that uses PHP as an Apache module. As PHP working mode becomes thread based, it will greatly reduce the resources usage and can generally handle more connections.

 

3. Fixing permissions and internal links

Last and not the least, fixing permissions of the files and folders also solve PHP resource usage problem in some cases. We analyze the user permissions and assign proper privileges to the Windows users. Similarly, we also adjust the firewall settings to allow certain IP addresses or tweak antivirus on the server. This would help to prevent any block on receiving content from another server.

[Is your Windows server always on 100% CPU usage? We’ll help you identify the reason and fix it.]

 

Conclusion

In short, php-cgi.exe high CPU usage happens mainly due to malformed PHP scripts, wrong IIS server settings and more. Today, we saw the typical reasons that would shoot up CPU usage on the server and how our Support Engineers identify and fix the problem.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

3 Comments

  1. Muhammad Mohsin

    AWS billed me exponentially higher this month for my ec2 burstable instance. After reading this article, i checked my cpu utilization which was 100%, that was the reason for higher bill. Did the iis settings you mentioned and cpu utilization decreased dramatically. My wordpress site got hacked sometime ago and i am sure thats the reason for cgi / fast cgi was consuming higher cpu.

    Can you help me find that malicious script?

    Reply
    • Sijin George

      Hello Muhammad,
      Glad to know that the post was useful.
      Yes, we can help you find the malicious script. If you still need help, we’ll be happy to talk to you on chat (click on the icon at right-bottom).

      Reply
  2. Muhammad Athar

    2. Adjusting PHP settings

    This post is usefull for me.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF