Often we (php developers) need to log certain messages in order to debug our script.しばしば私たち( PHPの開発者が)必要であれば、特定のメッセージをログに記録するためのスクリプトをデバッグする。 Here I will describe the default syslog method and a much simpler (and better) way to log your messages quickly and painlessly.ここで私は、デフォルトのsyslogの方法を説明すると、よりシンプルな(そしてより良い)の方法をログに記録してメッセージをすばやく手軽にします。

PHP manual suggests usingを使用してPHPマニュアルを示唆 syslog syslogに for logging.ログを記録します。

Problems with 問題が発生 syslog syslogに
The problem with syslog is that its implementation is system dependent. syslogに問題があるのは、その実装はシステム依存です。 For example openlog() is not supported on windows.例えば、 openlog ( )ではないのWindowsでサポートされています。

The location of the logged data is system dependent, which you may not have access to (if you are on a shared web hosting environment) or know about.場所はログに記録するデータはシステムに依存、これにアクセスすることはできません(場合にはウェブホスティング環境で使用する共有) 、または知っている。

The procedure is more cumbersome than you may like to undertake for simple quick and dirty log messages.この手順は、他の煩雑なことがありますように着手をより迅速かつ簡単な汚いログメッセージを表示します。

Using syslog を使用してのsyslog
Here is a sample code using syslog:次に示すのは、サンプルコードを使用してのsyslog :

< ?php <ですか? PHPの
define_syslog_variables(); するdefine_syslog_variables ( ) ;
// open syslog, include the process ID and also send / / syslogに開いて、送信するには、プロセスID 、また
// the log to standard error, and use a user defined / /ログを標準エラー出力、およびユーザ定義を使用する
// logging mechanism / /ログ機構
openlog(”myScriptLog”, LOG_PID | LOG_PERROR, LOG_LOCAL0); openlog ( " myscriptlog " 、 log_pid | log_perror 、 log_local0 ) ;

// some code / /いくつかのコード

if (authorized_client()) {もし( authorized_client ( ) ) (
// do something / /何か
} else { )他(
// unauthorized client! / /許可されていないクライアントから!
// log the attempt / /ログの試み
$access = date(”Y/m/d H:i:s”); $アクセス=日付( " y /月/ d h :私:秒" ) ;
syslog(LOG_WARNING, “Unauthorized client: $access $_SERVER[REMOTE_ADDR] ($_SERVER[HTTP_USER_AGENT])”);のsyslog ( log_warning 、 "許可されていないクライアント: $アクセス$ _server [のREMOTE_ADDR ] ( $ _server [ http_user_agent ])");
}

closelog();するcloselog ( ) ;
?>ですか? >

Simpler alternative シンプルな代替
Now lets look into a quicker and simpler alternative for your simple logging needs.今すぐ見てみましょうをすばやく簡単に代替お客様のニーズにシンプルなログ出力します。
file_put_contents file_put_contents (’log_file_name’, $data, FILE_APPEND); ( ' log_file_name ' 、 $データ、 file_append ) ;

$data is the data you want logged. $データはログに記録されたデータを選択します。 You can also pass in an array.パスの配列をすることもできます。 This creates a file in the directory the script is invoked from and appends your log messages.このファイルを、ディレクトリを作成するスクリプトが呼び出されるからと付加してログメッセージを表示します。