Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Excessive Resource usage by PHP : How to find the exact cause?

Discussion in 'General Discussion' started by martin MHC, Oct 5, 2017.

  1. martin MHC

    martin MHC Active Member

    Joined:
    Sep 14, 2016
    Messages:
    43
    Likes Received:
    6
    Trophy Points:
    8
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    I have an account on the server that's been merrily normal forever. Yesterday I adjusted an included PHP file (included into index.php):



    And since this change started getting persitent server notifications of:

    Time: Thu Oct 5 13:18:27 2017 +0100
    Account: accountname
    Resource: Process Time
    Exceeded: 62126 > 7500 (seconds) Executable: /cdf/cpanel/ea-php56/.../php-cgi
    Command Line: /cdf/cpanel/.../php-cgi> /home3/accountname/public_html/index.php
    PID: 3668 (Parent PID: 2416)
    Killed: No​

    Now, I can clearly see that the issue is somehow the /home3/accountname/public_html/index.php file, but I have no Apache error logs for this account and no PHP errors (even with error_reporting(E_ALL)).

    I have also explored the daily process log for CPU usage and this is negligable, so it's definitely a PHP / Memory issue.

    The issue does not appear on local-machine testing of the page.

    These error logs are comming in at ~20 an hour, for the last 6 hours and I can't find a way of establishing which part of the PHP file is causing the exceedage?

    While other posts on here states the issue may be with FastCGI (which is used here, see above), but

    i) This has not been an issue previously. and

    ii) Only this account (of many) is effected.

    iii) Only the index.php file is effected

    How do I find which part of the PHP file is draining the server memory?

    NOTE:
    I don't want to ignore this issue; as all the other posts seem to suggest, I want to be able to view the cause of the issue to establish for myself if I should ignore it or fix some memory gobbling code (a while statement maybe).
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    15,745
    Likes Received:
    312
    Trophy Points:
    433
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Out of curiousity, if you reverse these changes does the issue go away?
     
  3. martin MHC

    martin MHC Active Member

    Joined:
    Sep 14, 2016
    Messages:
    43
    Likes Received:
    6
    Trophy Points:
    8
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    No. reverting the changes does not cease the notifications. Even if it did, I'd still like to know how the best way of finding which part of a file causes this issue, if it's logged and if so where to find this log. Cheers
     
  4. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    15,745
    Likes Received:
    312
    Trophy Points:
    433
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Indeed. Have you checked the directory that file is in for a file called error_log?
     
  5. martin MHC

    martin MHC Active Member

    Joined:
    Sep 14, 2016
    Messages:
    43
    Likes Received:
    6
    Trophy Points:
    8
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    Yes, there are no error logs that I've found, as I said.

    By your line of questions, I should maybe clarify that while this is an issue, my motive to post here is how to debug this and similar issues in the future; rather than simply getting a specific answer for this specific case (although that would also be good!).

    If the generated server error log is able to tell me which part of the file is causing the excessive usage?

    Thank you for your help though :)
     
  6. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    15,745
    Likes Received:
    312
    Trophy Points:
    433
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    No clue.
    What did you change exactly?
     
  7. martin MHC

    martin MHC Active Member

    Joined:
    Sep 14, 2016
    Messages:
    43
    Likes Received:
    6
    Trophy Points:
    8
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    Hello.
    I setup using mb_ functions for string work turning strlen into mb_strlen

    It is not something I would expect to use excessive resources and the publicfacing side of the pages works fine, such as there's no delay in page output etc. indicative of a code issue (such as infinite looping).
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,424
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Is PHP-FPM enabled for this domain name? If so, you may also want to review the PHP-FPM error log at:

    Code:
    /opt/cpanel/ea-php$$/root/usr/var/log/php-fpm/error.log
    Replace "ea-php$$" with the version of PHP assigned to the account.

    Thank you.
     
  9. martin MHC

    martin MHC Active Member

    Joined:
    Sep 14, 2016
    Messages:
    43
    Likes Received:
    6
    Trophy Points:
    8
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    Hi Michael,
    Thanks for suggestion. PHP FPM is not installed in these accounts. PHP version is 5.6.

    I have resolved the issue itself by rebooting the server. But my query still remains in principle how to investigate exact causes in PHP scripts of excessive resource usage notifications.

    Cheers
     
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,424
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    There's no set guidelines on how to determine the cause of a PHP script using excessive resources, but you may find the following StackOverflow discussions helpful:

    PHP and MySQL: Find out which file or query is causing heavy CPU load
    How to find which PHP script is leaking memory?
    Determining a PHP script's execution time
    find which function(file) causes server overload

    Additionally, the following thread is useful for troubleshooting overall load issues:

    Troubleshooting high server loads on Linux servers

    Thank you.
     
Loading...

Share This Page