Created
December 5, 2014 18:13
-
-
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.
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 | |
$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