Skip to content

Instantly share code, notes, and snippets.

@krhoyt
Created December 5, 2014 18:13
Show Gist options
  • Save krhoyt/46ffd9f5179a4807a248 to your computer and use it in GitHub Desktop.
Save krhoyt/46ffd9f5179a4807a248 to your computer and use it in GitHub Desktop.
Basic example of publishing to PubNub from PHP. Really distilled down to just the REST calls.
<?php
$CHANNEL = "iot";
$PUB_KEY = "_YOUR_PUBLISH_KEY_";
$SUB_KEY = "_YOUR_SUBSCRIBE_KEY_";
$SECRET_KEY = "_YOUR_SECRET_KEY_";
$PUBNUB = "http://pubsub.pubnub.com";
$data = array(
"count" => 3
);
$message = urlencode( json_encode( $data ) );
$uuid = uniqid();
$url = $PUBNUB . "/publish/" . $PUB_KEY . "/" . $SUB_KEY . "/" . $SECRET_KEY . "/" . $CHANNEL . "/0/" . $message . "?uuid=" . $uuid;
echo $url . "\n";
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $curl );
curl_close( $curl );
echo $response . "\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment