phpday 2027 - Call for Papers

openlog

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

openlog — Abre la conexión al historial del sistema

Descripción

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

openlog() abre la conexión al historial del sistema.

El uso de openlog() es opcional. Si no ha sido llamada, la conexión se abre con el primer mensaje que se registra. Cuando ese mensaje proviene de syslog(), entonces en PHP 8.1 a 8.3, hasta PHP 8.4.27 y hasta PHP 8.5.12, el prefijo y la facilidad (facility) se dejan a cargo del sistema (el prefijo suele ser el nombre del programa, y php en Windows), y las directivas INI syslog.ident y syslog.facility no se utilizan. Cuando proviene de error_log o de mail.log configurado como syslog, esas directivas sí se utilizan.

Parámetros

prefix

El string prefix será añadido a cada mensaje.

flags

Máscara de bits de las constantes siguientes:

facility

El argumento facility se utiliza para especificar el tipo de programa que registra el mensaje. Esto permite al fichero de configuración especificar que los mensajes provenientes de diferentes instalaciones serán tratados de manera distinta. Debe ser una de las constantes siguientes:

Nota:

Este parámetro es ignorado en Windows.

Valores devueltos

Retorna siempre true.

Historial de cambios

Versión Descripción
8.2.0 La función ahora siempre retorna true. Anteriormente, retornaba false en caso de fallo.

Véase también

  • syslog() - Genera un mensaje en el historial del sistema
  • closelog() - Cierra la conexión al registro del sistema

User Contributed Notes 1 note

up
2
Nimja
13 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));
    }
}
?>
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top