Stop printing php error messages to browser

2020-03-12 03:33发布

I'm using PHP 5.3, CentOS 6.2, httpd 2.2.15, NetBeans 7.0.1 (running remotely via ftp).

I want to stop printing error messages to the browser, it's enough that it prints to the error_log of httpd.

I thought by doing try/catch I would decide on my own how to handle the error but it still prints to both error_log and browser.

function smic_gettext($phrase){

        try{
            $tr_text = $this->language_array[$phrase];

        } catch(Exception $e){
            error_log("Couldn't find any entry in the translation file for ".$phrase.". ".$e);
            return $phrase;

        }

        return $tr_text;
    } 

How should I configure in order to stop this behaviour?

I have tried setting display_errors=Off and display_errors=0 in php.ini. No difference (I did restart httpd).

8条回答
对你真心纯属浪费
2楼-- · 2020-03-12 04:24

If you want to hide errors and warnings, you can also set an error_handler.

See http://php.net/manual/function.set-error-handler.php

查看更多
淡お忘
3楼-- · 2020-03-12 04:26

FWIW, while display_errors = off is the correct config-file line as others have said, on DreamHost (nd possibly other installations), it goes in

$HOME/.php/phprc

rather than php.ini (which might also work, but DreamHost -- and, again, possibly others -- supports phprc).

查看更多
登录 后发表回答