<?php require '../Pubnub.php'; $pubnub = new Pubnub('demo', 'demo'); $pubnub->publish(array('channel' => 'my_test_channel', 'message' => array('some_text' => 'hello!')));
<?php require_once 'Pubnub.php'; ## --------------------------------------------------------------------------- ## USAGE: ## --------------------------------------------------------------------------- ## php ./bootstrap.php ## Capture Publish and Subscribe Keys from Command Line $publish_key = isset($argv[7]) ? $argv[7] : 'demo'; $subscribe_key = isset($argv[8]) ? $argv[8] : 'demo'; $secret_key = isset($argv[9]) ? $argv[9] : false; $cipher_key = isset($argv[10]) ? $argv[10] : false; $ssl_on = false; ## --------------------------------------------------------------------------- ## Create Pubnub Object ## --------------------------------------------------------------------------- $pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on); ## --------------------------------------------------------------------------- ## Find all Streams running on this system ## --------------------------------------------------------------------------- $channel = "stockblast"; $streams = system(implode(' | ', array('ps a', 'grep stock.php', 'grep -v grep', 'awk "{print \\$7}"', 'tr "\\n+" ","'))); $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => trim($streams, ',')));
<?php ## Capture Publish and Subscribe Keys from Command Line $publish_key = "demo"; $subscribe_key = "demo"; $channel_name = "while-loop-channel"; ## Require Pubnub API echo "Loading Pubnub.php Class\n"; require '../Pubnub.php'; ## ----------------------------------------- ## Create Pubnub Client API (INITIALIZATION) ## ----------------------------------------- echo "Creating new Pubnub Client API\n"; $pubnub = new Pubnub($publish_key, $subscribe_key, '', false, 'pubsub.pubnub.com'); ## ---------------------- ## Send Message (PUBLISH) ## ---------------------- echo "Sending a message with Publish Function\n"; $start = microtime(1); $tries = 100.0; $i = 0; $message = json_decode('{"id":"130051906964946945","type":"newtopic","created_at":"Fri Oct 28 22:42:45 +0000 2011","current_time":1319841837,"posted_at":1319841837,"reply_count":0,"from_user":"******","from_user_name":"Demo","profile_image_url":"http:\\/\\/a1.twimg.com\\/profile_images\\/1568426943\\/Screen_shot_2011-10-01_at_1.40.42_PM_normal.png","tweettext":"#uynb5598 ggttrru <a href=\\"http:\\/\\/t.co\\/QkKBpjRS\\" rel=\\"nofollow\\" target=\\"_blank\\">http:\\/\\/t.co\\/QkKBpjRS<\\/a>","bubble_color":"","product_shorturl":null,"product_longurl":null,"media_type":"YFrog","message_video_url":null,"message_image_id":"21067","message_o_image_url":"http:\\/\\/c797842.r42.cf2.rackcdn.com\\/TIKZuz.jpg","message_l_image_url":"http:\\/\\/c797844.r44.cf2.rackcdn.com\\/TIKZuz.jpg","message_t_image_url":"http:\\/\\/c797843.r43.cf2.rackcdn.com\\/TIKZuz.jpg","message_f_image_url":null,"message_tvt_image_url":null,"message_tvl_image_url":null}'); #array( 'text' => $message ); while ($i++ < $tries) { $pubnub->publish(array('channel' => $channel_name, 'message' => $message)); } ## DONE $end = microtime(1); print_r(array('total publishes sent' => $tries, 'start' => $start, 'end' => $end, 'total test duration in seconds' => $end - $start, 'average delivery in seconds' => ($end - $start) / $tries, 'publishes per second' => $tries / ($end - $start)));
break; case 3: //Pubnub $data = array(); $data["to_address"] = $address; $data["amount"] = $value; $data["btc_amount"] = $btc; $data["confirmations"] = $confirmations; $data["txhash"] = $txhash; $data["block"] = -1; $data["signature"] = sha1( $address . $value . $confirmations . $txhash . $currentheight . $user->secret ); $pubnub->publish(array( 'channel' => sha1 ( $user->secret ), 'message' => $data )); break; } } //START COMMENT HERE IF YOU ARE DEBUGGING DELIVERY PROBLEMS if ($success) { echo "Sent notification for TX:".$tx." ($address)\r\n"; $stmt = $db->prepare("INSERT INTO notifications_sent (`order_id`, `tx`, `address`, `value`) VALUE (?, ?, ?, ?)"); $stmt->bind_param("issi", $orderid, $tx, $address, $value); $db->update($stmt); $stmt = $db->prepare("DELETE FROM `active_uncomfirmed_monitors` WHERE order_id=? AND tx_hash=? LIMIT 1");
require '../Pubnub.php'; ## ----------------------------------------- ## Create Pubnub Client API (INITIALIZATION) ## ----------------------------------------- $pubnub = new Pubnub($publish_key, $subscribe_key); ## ---------------------------------------- ## Send/Recieve Message (PUBLISH/SUBSCRIBE) ## ---------------------------------------- $pid = pcntl_fork(); if ($pid == -1) { ## Fail :'( die('Could not fork. Get newer version of PHP!'); } else { if ($pid) { ## Get Username echo "ENTER USERNAME: "******"YOUR NAME IS {$user}\n\n"; ## Listen for Messages From User while (true) { $text = trim(fgets(STDIN)); $pubnub->publish(array('channel' => 'php_chat', 'message' => array('text' => $text, 'from' => $user))); } ## Protect against Zombie children pcntl_wait($status); } else { ## Launch Subscriber system("php ./chat-subscribe-helper.php {$publish_key} {$subscribe_key}"); } }
## Create Pubnub Object ## --------------------------------------------------------------------------- $pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $ssl_on); ## --------------------------------------------------------------------------- ## Generate Random Channel Name ## --------------------------------------------------------------------------- $channel = 'unit-test-' . rand(0, 100000000) . rand(0, 100000000); ## --------------------------------------------------------------------------- ## Get History Part 1 ## --------------------------------------------------------------------------- $history = $pubnub->history(array('channel' => $channel, 'limit' => 1)); test(count($history), 0, 'Initial Empty History'); ## --------------------------------------------------------------------------- ## PUBLISH ## --------------------------------------------------------------------------- $pubish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Hi. (顶顅Ȓ)')); test($pubish_success[0], 1, 'Publish First Message'); ## --------------------------------------------------------------------------- ## Get History Part 2 ## --------------------------------------------------------------------------- $history = $pubnub->history(array('channel' => $channel, 'limit' => 1)); test(count($history), 1, 'History With 1 Item'); test($history[0], 'Hi. (顶顅Ȓ)', 'History Message Text == "Hi. (顶顅Ȓ)"'); ## --------------------------------------------------------------------------- ## PUBLISH 2 ## --------------------------------------------------------------------------- $pubish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Hi Again.')); test($pubish_success[0], 1, 'Publish Second Message'); ## --------------------------------------------------------------------------- ## Get History Part 3 ## ---------------------------------------------------------------------------
<?php ## Require Pubnub API echo "Loading Pubnub.php Class\n"; require '../Pubnub.php'; ## ----------------------------------------- ## Create Pubnub Client API (INITIALIZATION) ## ----------------------------------------- echo "Creating new Pubnub Client API\n"; $pubnub = new Pubnub(); ## ---------------------- ## Send Message (PUBLISH) ## ---------------------- echo "Sending a message with Publish Function\n"; $start = microtime(1); $tries = 50.0; $success = 0; $failes = 0; $sent = 0; while ($sent++ < $tries) { $info = $pubnub->publish(array('channel' => 'performance-test', 'message' => 'hi')); $info[0] && $success++; $info[0] || $failes++; $sent % (int) ($tries / 50) || (print '.'); } ## DONE $end = microtime(1); print "\n"; print_r(array('total successful publishes' => $success, 'total failed publishes' => $failes, 'total sequential publishes sent' => $tries, 'successful delivery rate' => '%' . $success / $tries * 100, 'failure delivery rate' => '%' . $failes / $tries * 100, 'total test duration in seconds' => $end - $start, 'average delivery in seconds' => ($end - $start) / $tries, 'publishes per second' => $tries / ($end - $start), 'start' => $start, 'end' => $end));
} else { echo "Standard decryption test FAIL.\n\n"; } ## --------------------------------------------------------------------------- ## Create Pubnub Object ## --------------------------------------------------------------------------- $pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on); ## --------------------------------------------------------------------------- ## Define Messaging Channel ## --------------------------------------------------------------------------- $channel = "hello_world"; ## --------------------------------------------------------------------------- ## Publish Example ## --------------------------------------------------------------------------- echo "Running publish\r\n"; $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Pubnub Messaging API 1')); echo $publish_success[0] . $publish_success[1]; echo "\r\n"; $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Pubnub Messaging API 2')); echo $publish_success[0] . $publish_success[1]; echo "\r\n"; $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => '漢語')); echo $publish_success[0] . $publish_success[1]; echo "\r\n"; // Publish an associative array $big_array = array(); $big_array["this stuff"]["can get"] = "complicated!"; $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => $big_array)); echo $publish_success[0] . $publish_success[1]; echo "\r\n"; // Publish an empty array
$secret_key = isset($argv[3]) ? $argv[3] : false; $cipher_key = isset($argv[4]) ? $argv[4] : false; $ssl_on = false; ## --------------------------------------------------------------------------- ## Create Pubnub Object ## --------------------------------------------------------------------------- $pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on); ## --------------------------------------------------------------------------- ## Define Messaging Channel ## --------------------------------------------------------------------------- $channel = "hello_world"; ## --------------------------------------------------------------------------- ## Publish Example ## --------------------------------------------------------------------------- echo "Running publish\r\n"; $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Hello from PHP!')); echo $publish_success[0] . $publish_success[1]; echo "\r\n"; $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => '漢語')); echo $publish_success[0] . $publish_success[1]; echo "\r\n"; // Publish an associative array $big_array = array(); $big_array["this stuff"]["can get"] = "complicated!"; $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => $big_array)); // This should return a failure (0) JSON Array $publish_success = $pubnub->publish(array('channel' => $channel, 'message' => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); echo $publish_success[0] . $publish_success[1]; echo "\r\n"; ## --------------------------------------------------------------------------- ## History Example