Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Submitting data to Honeycomb from PHP 5
<?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);
}
?>
@wrigby

This comment has been minimized.

Copy link
Owner Author

@wrigby wrigby commented May 13, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.