Last active
May 13, 2020 23:23
-
-
Save wrigby/c8321374977c9391b05ed3a385828ce2 to your computer and use it in GitHub Desktop.
Submitting data to Honeycomb from PHP 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Send some data to Honeycomb, where $data is just an associative array | |
// that can be JSON encoded. Wire this up in a callback with | |
// `register_shutdown_function` to ship data off after your request is finished. | |
function send_data($dataset, $data) { | |
$url = 'https://api.honeycomb.io/1/events/'.$dataset; | |
$team_id = 'secret'; | |
$timestamp = microtime(True); | |
$options = array( | |
"http" => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n". | |
"X-Honeycomb-Team: $team_id\r\n". | |
"X-Honeycomb-Event-Time: $timestamp\r\n", | |
'method' => 'POST', | |
'content' => json_encode($data) | |
) | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ripped this out from some prod code and it's probably not worthy of being called best practice - just a quick and dirty example! Not tested; I may have missed some stuff when adapting it from my application's internal context.