PHP 8.4.2 Released!

openlog

(PHP 4, PHP 5, PHP 7, PHP 8)

openlogOpen connection to system logger

说明

openlog(string $prefix, int $flags, int $facility): true

openlog() opens a connection to the system logger for a program.

The use of openlog() is optional. It will automatically be called by syslog() if necessary, in which case prefix will default to the empty string.

参数

prefix

The string prefix is added to each message.

flags

Bitmask of the following constants:

facility

The facility argument is used to specify what type of program is logging the message. This lets the configuration file specify that messages from different facilities will be handled differently. Must be one of the following constants:

注意: This parameter is ignored on Windows.

返回值

总是返回 true

更新日志

版本 说明
8.2.0 The function now always returns true. Previously it returned false on failure.

参见

添加备注

用户贡献的备注 1 note

up
1
Nimja
11 years ago
To those curious; switching between different facilities is NOT an issue. There is no apparent memory overhead (nor slowdown) by calling openlog multiple(12 * 10000) times.

Shown by this example:

<?php
$facilities
= array(
LOG_AUTH,
LOG_AUTHPRIV,
LOG_CRON,
LOG_DAEMON,
LOG_KERN,
LOG_LOCAL0,
LOG_LPR,
LOG_MAIL,
LOG_NEWS,
LOG_SYSLOG,
LOG_USER,
LOG_UUCP,
);

for (
$i = 0; $i < 10000; $i++) {
foreach (
$facilities as $facility) {
openlog('test', LOG_PID, $facility);
syslog(LOG_ERR, "This is a test: " . memory_get_usage(true));
}
}
?>
To Top