syslog()
syslog() — Generate a system log message.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
syslog() generates a log message that will be distributed by the system logger.
Signature
syslog(int $priority, string $message): true
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $priority | int | One of the LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG constants. |
| $message | string | The message to send. |
Return value
Always returns true.
Example
A runnable snippet:
// open syslog, include the process ID and also send // the log to standard error, and use a user defined // logging mechanism openlog("myScriptLog", LOG_PID | LOG_PERROR, LOG_LOCAL0); // some code if (authorized_client()) { // do something } else { // unauthorized client! // log the attempt $access = date("Y/m/d H:i:s"); syslog(LOG_WARNING, "Unauthorized client: $access {$_SERVER['REMOTE_ADDR']} ({$_SERVER['HTTP_USER_AGENT']})"); } closelog();
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page syslog() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.