简体   繁体   中英

Hide common PHP warning and Notices

Plot: First I had a site with GodDaddy, Furstated of their cool CPanel and more cool downtimes I moved on to Digital Ocean VPS.

Problem: But when I transferred files to VPS I get some common/uncommon PHP errors. I seen no errors when using godaddy. A few of them are.

Notice: Undefined variable: q in /srv/users/someuser/apps/video/public/config.php on line 7

and

Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead 

I am using PHP 5.4 (on nginx , the LEMP install)for now. Any way to hide these errors as my site is working flawlessly even when these errors appear.

Instead of suppressing notices and error messages, I would consider fixing the problems. Might be more work to do for now, but I think it's worth the effort in order to have a full running and functioning program in the end - and if Digital Ocean updates libraries your code will break.

Notice: Undefined variable: q in /srv/users/someuser/apps/video/public/config.php on line 7

this notice tells you that there is a variable not set and in which file and in which line. So you should just go to this file, have a look on what is happening in line 7 and try to fix it. It looks like $q isn't needed at all, so try to comment the line out or take a deeper look in your file if the variable is needed elsewhere.

Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead 

CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead.

Consider having a look in the file you are running curl and change the line from either

CURLOPT_SSL_VERIFYHOST => true or  CURLOPT_SSL_VERIFYHOST => 1

to:

CURLOPT_SSL_VERIFYHOST => 2,

Looks like GoDaddy used outdated (older) versions of the different libraries.

The curlopt setting may be a warning right now, but will break your program as soon as Digital Ocean updates their libraries or you update them.

You can change your php.ini file according to the documentation and avoid the error :

error_reporting = E_ALL & ~E_NOTICE

This will remove notices and coding standards warnings.

在脚本顶部添加以下内容

 error_reporting(0);

In your php.ini file, there are two variables for you consider. The first one is for the level of errors captured, and the second is whether or not to show them on the screen.

error_reporting = E_ALL & ~E_DEPRECATED

display_errors = Off

Adjusting these will give you the desired output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM