Skip to content

Instantly share code, notes, and snippets.

@wrigby
Last active May 13, 2020 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrigby/c8321374977c9391b05ed3a385828ce2 to your computer and use it in GitHub Desktop.
Save wrigby/c8321374977c9391b05ed3a385828ce2 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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