William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

PHP: 2 tips to avoid logfile warnings

1. timezone warning in error log

When using Apache as webserver, if not setup properly, some apps(like smarty templates) will generate error/warning in error_log. e.g.: when not setup timezone by default, there will be warnings in PHP’s error_log:

PHP Warning: strftime(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function…

This will write into error.log frequently, to make it increasing quickly and badly, which we don’t want and have to avoid it.
To prevent from it, it is easy, here are my 2 solutions:
(1) in php.ini file, Add timezone ‘America/Vancouver’ to setup default:

//1. add timezone php config file:
$ sudo vi /etc/php.ini
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = 'America/Vancouver';

//2. restart server:
$ sudo /etc/init.d/httpd restart

(2) Or, adding the following codes in app config file as a global setting:

$timezone = "America/Vancouver";

By the settings, it won’t generate timezone warnings anymore; There will be no waring reports to httpd’s error_log file, so clear up the log file.

2. redirect script to avoid repeated warnings in error_log:

PHP scripts could occur this kind of repeated warnings in httpd error_log:

[] PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in foo.php on line 246…

This kind of scripts are deprecated; however, google search crawler still look up for it, to generate meaning errors repeatedly.
To avoid it: just let google crawler to pass it, not execute, to redirect the PHP script:

// $ vi +246 foo.php:
public function test($param) {
 //add something like this to return directly instead of executing:
 return array();
 return mysql_fetch_assoc($res);
// Or:
ini_set('date.timezone', $timezone);

This way will prevent the google’s execute of the function so to avoid the warning output.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: