Skip to content

Instantly share code, notes, and snippets.

@luxerama
Forked from troy/send_remote_syslog.php
Created May 13, 2012 21:06
Show Gist options
  • Save luxerama/2690211 to your computer and use it in GitHub Desktop.
Save luxerama/2690211 to your computer and use it in GitHub Desktop.
Send UDP remote syslog message from PHP (RFC 3164)
<?php
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$msg = "<22>" . date('M j H:i:s ') . $program . ' ' . $component . ': ' . $message;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
# replace these with settings provided by Papertrail
socket_sendto($sock, $msg, strlen($msg), 0, 'logs.papertrailapp.com', 1111);
socket_close($sock);
}
send_remote_syslog("Test");
# send_remote_syslog("Any log message");
# send_remote_syslog("Something just happened", "other-component");
# send_remote_syslog("Something just happened", "a-background-job-name", "whatever-app-name");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment