display_errors = Off and still errors printed in CLI

Discussion in 'PHP' started by PSS, Mar 24, 2018.

  1. PSS

    PSS Well-Known Member

    I have set display_errors = Off and error logging to file. That ini (/opt/lsws/lsphp7/lib/php.ini) is loaded and used.

    Problem:
    I have cron scripts (php) running and was surprised to see the notice error printed (which prevented php generated mails going out):
    Code:
    Notice: Undefined variable: xxxxxxxxx in /..../.php
    on line 3852
    I verified this behaviour:

    if I run a script in CLI
    PHP:
    <?php

    p hpinfo
    (INFO_GENERAL);

    ?>
    I get
    Code:
    Parse error: syntax error, unexpected 'hpinfo' (T_STRING) in /root/phpinfo.php on line 3
    I really should not see ANY errors printed out!

    Any ideas?
    It looks like CLI uses some other ini even if it says it uses the /opt/lsws/lsphp7/lib/php.ini, or simply ignores it.
    I don't want to use error_reporting(0); because I need to see logged errors.



    ini file is loaded correctly (where "display_errors = Off"):
    phpinfo(INFO_GENERAL) run (that same php script above in correct form) in shell shows
    Code:
    PHP Version => 7.2.3
    Server API => LiteSpeed V7.0
    Loaded Configuration File => /opt/lsws/lsphp7/lib/php.ini
    Scan this dir for additional .ini files => (none)
    Additional .ini files parsed => (none)
    PHP API => 20170718
    PHP Extension => 20170718
    Zend Extension => 320170718
    Zend Extension Build => API320170718,NTS
    PHP Extension Build => API20170718,NTS
    Debug Build => no
    (LSWS Enterprise 4-CPU 5.2.5)
     
    Last edited by a moderator: Mar 26, 2018
  2. mistwang

    mistwang LiteSpeed Staff

    you can use a different php.ini for the cron job by using "-c ..." option.
     
    Đức Cảnh likes this.
  3. PSS

    PSS Well-Known Member

    Yes I know. No matter what you have there, errors are printed (lsws updated to latest release).
    Code:
    /opt/lsws/fcgi-bin/lsphp7 -c /opt/lsws/lsphp7/lib/php_x.ini ./phpinfo.php
    
    Parse error: syntax error, unexpected 'hpinfo' (T_STRING) in /root/phpinfo.php on line 3
    php_x.ini contains
    Code:
    error_reporting = E_ALL
    display_errors = Off
    display_startup_errors = Off
    log_errors = Off
    log_errors_max_len = 1024
    ignore_repeated_errors = On
    ignore_repeated_source = On
    report_memleaks = On
    html_errors = Off
    error_log =
    if I set in ini
    Code:
    error_reporting = 0
    the errors won't show up, but that does not negate this problem. I really want to ONLY log all errors, but now it is impossible in CLI as it prints all out regardless of ini settings.

    PHP:
    error_reporting(0); 
    in php file does not hide errors,
    error_reporting = 0 in ini is the only one that works with CLI.
     
    Last edited by a moderator: Mar 27, 2018
  4. Tishu

    Tishu Well-Known Member

    Hello,
    Can you post output of:

    Code:
    php -v
    whereis php
     
    Last edited by a moderator: Mar 27, 2018
  5. PSS

    PSS Well-Known Member

    Those produce no result, but it brought out something useful.
    I have in the system php binaries

    Code:
    /opt/lsws/lsphp7/bin/lsphp
    /opt/lsws/lsphp7/bin/php
    /opt/lsws/fcgi-bin/lsphp
    /opt/lsws/fcgi-bin/lsphp-7.2.3
    /opt/lsws/fcgi-bin/lsphp7
    /opt/lsws/fcgi-bin/lsphp4
    /opt/lsws/fcgi-bin/lsphp5
    and I found the only one that is actually CLI php is

    Code:
    /opt/lsws/lsphp7/bin/php -v
    PHP 7.2.3 (cli) (built: Mar  5 2018 13:41:36) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.2.3, Copyright (c) 1999-2018, by Zend Technologies
    
    Loaded Configuration File => /opt/lsws/lsphp7/lib/php.ini
    
    And so that is the only one that honors the correct ini and does not output errors in CLI mode.

    I must say this lsws php setup is quite confusing.
     

Share This Page