PHP / MySQL üzerine uyarıları ve hataları kapatın

6 Cevap php

Beklediğim bildirimler ve uyarılar alıyorum ve benim php dosyasında bunları kapatmak istiyorum. hataları şunlardır:

Warning: fsockopen()

ve uyarılar şunlardır:

Notice: A non well formed numeric value encountered in

Ben bu php komut dosyası için cron kullanmayı planlıyorum, ve her yerde ... yani cpanel hata vb oturum açmış herhangi bir hata veya bildirimini almak istemiyorum ..

6 Cevap

Php script başında bu satırı koyun: Eğer komut mükemmel çalıştığından emin olduğunuzda, Uyarı ve bu gibi bildirimlerin kurtulabilirsiniz:

error_reporting(E_ERROR);

Before that, when working on your script, i would advise you to properly debug your script so that all notice or warning disappear one by one. So you should first set it as verbose as possible with:

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

UPDATE : how to log errors instead of displaying them As suggested in the comments, the better solution is to log errors into a file so only the php developer sees the error messages, not the users. A possible implementation is via the .htaccess file, useful if you don't have access to the php.ini file (source).

# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
# enable PHP error logging
php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log
# prevent access to PHP error log
<Files PHP_errors.log>
 Order allow,deny
 Deny from all
 Satisfy All
</Files>

TÜM hata raporlama kapatarak aksine, bazı hatalarını bastırmak için '@' sembolü ile Prepend fonksiyonlar.

Daha Fazla Bilgi: http://php.net/manual/en/language.operators.errorcontrol.php

PHP bir hata kontrol operatörü destekler: at işareti (@). PHP bir ifadeye önüne, o ifade tarafından oluşturulan olabilir herhangi bir hata iletileri göz ardı edilecektir.

@fsockopen();

Her test sunucusuna hataları göstermek. Üretim sunucusunda hataları göstermek asla.

Sayfa bir yerel, test veya canlı sunucuda olup olmadığını belirlemek, ve "yerel", "test", ya da "canlı" $ durumunu ayarlamak için bir senaryo yazın. Daha sonra:

if( $state == "local" || $state == "testing" )
{
 ini_set( "display_errors", "1" );
 error_reporting( E_ALL & ~E_NOTICE );
}
else
{
 error_reporting( 0 );
}

Eğer php.ini de veya komut üstüne error_reporting () işlevini kullanarak ihtiyaç raporlama hata türünü ayarlayabilirsiniz.

. Nedense php.ini dosyasına alamıyorsanız, aşağıdaki satırı ekleyerek herhangi bir dizinde bir htaccess dosyası (display_errors) Stdout'a hatalarını devre dışı bırakın:

php_flag display_errors off

ayrıca, bir dosyaya hata günlüğü ekleyebilirsiniz:

php_flag log_errors on

PHP error_reporting referans:

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);