// Log error message $errorMsg = "An error occurred!"; error_log($errorMsg); // Trigger alert for critical errors if ($errorCode == 500) { trigger_error($errorMsg, E_USER_ERROR); }
// Log access to protected resource $userId = 1234; $username = "john_doe"; access_log("$userId,$username", "protected_resource"); // Trigger alert for unauthorized access attempts if (!$isAuthorized) { mail("admin@example.com", "Unauthorized access alert", "User $username attempted to access protected_resource"); }In this example, we log access to a protected resource using the `access_log()` function, which takes the user ID and username as parameters along with the resource name. We then check whether the access is authorized and send an email alert to the system administrator if it is not. The PHP Log alert feature can be implemented using various packages and libraries such as Monolog, Log4PHP, and PHPLogger. These packages provide advanced features for logging and alerting, such as different log levels, message formatting, and email alerts.