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.

Function hook php error log?

Discussion in 'cPanel Developers' started by robagar, Jan 13, 2011.

  1. robagar

    robagar Member

    Joined:
    Jan 13, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    hi all

    I'm writing hooks for the AddonDomain module in php and having trouble. Simple tests work, so I know the hooks are registered ok. Do php errors get logged anywhere?

    cheers
    Rob
     
    #1 robagar, Jan 13, 2011
    Last edited: Jan 13, 2011
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    It depends on which ini file you're using and the settings it has.

    If you're following the example from the function hook page, then your shebang line is
    Code:
    #!/usr/bin/php-cgi
    
    which means we can get the ini file location with
    Code:
    /usr/bin/php-cgi -i |grep --colour 'php.ini'
    <tr><td class="e">error_reporting</td><td class="v">6135</td><td class="v">6135</td></tr>
    
    Now we know which ini file to look at, /usr/local/lib/php.ini

    What we want to know is
    1) what/where the error log is defined to be
    2) if errors are redirected to the STDOUT
    3) if error reporting is enabled
    4) and if errors are even logged

    Code:
    awk '/(^error_log[[:space:]]?=)|(^display_errors[[:space:]]?=)|(^error_reporting[[:space:]]?=)|(^log_errors[[:space:]]?=)/{print $0};' /usr/local/lib/php.ini
    
    For my box, I got
    Code:
    display_errors = On
    log_errors = On
    error_log = /usr/local/cpanel/logs/error_log
    
    but your's is likely to be different. But lets quickly analyze my results.

    1) display_errors is "on". This means that any error message that would normally be sent to an error log will also be sent to STDOUT. This is not something that most people want in a production environment. In the case of function hooks this would not be a good setting since the output is trapped by the invoking cPanel process and will break the cPanel response (if any errors were to occur). Function hooks should never produce anything to STDOUT
    - You can modify this in your script with
    PHP:
    ini_set('display_errors'0);
    - Or better, change the setting in the ini
    - See display_errors in the PHP manual

    2) log_errors is on, meaning that any errors will be send to the "error_log" location.
    - See log_errors

    3) my error_log setting is the standard cPanel error log. This is something that I personally set on my box because it's a convenient place. I think the current default for this value on a cPanel installation is simply "error_log", which is Apache's error log, /usr/local/apache/logs/error_log

    PHP:
    ini_set('error_log''/some/place');
    - See error_log

    4) Since nothing was returned for error_reporting, the default is applied, "6135" or "E_ALL & ~E_NOTICE"
    - we can confirm this with a grep on the info output
    Code:
    /usr/bin/php-cgi -i |grep --colour error_reporting
    
    - See error_reporting


    Hope this helps get you going in the right direction.

    Regards,
    -DavidN
     
    #2 cPanelDavidN, Jan 14, 2011
    Last edited: Jan 14, 2011
  3. robagar

    robagar Member

    Joined:
    Jan 13, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Wow! thanks for the comprehensive reply :)
     
Loading...

Share This Page