Permalink
Browse files

moving repo

  • Loading branch information...
1 parent cafcb2d commit ebc561a2fc02d181d8759304f65dd2ed84d2daaf geremy committed Mar 20, 2013
Showing with 2 additions and 3,592 deletions.
  1. +0 −239 php/3.1/Pubnub.php
  2. +0 −8 php/3.1/examples/README
  3. +0 −52 php/3.1/examples/benchmark.php
  4. +0 −68 php/3.1/examples/chat-command-line.php
  5. +0 −38 php/3.1/examples/chat-subscribe-helper.php
  6. +0 −38 php/3.1/examples/history-example.php
  7. +0 −51 php/3.1/examples/performance-test.php
  8. +0 −4 php/3.1/examples/php-push-api-walkthrough-javascript-publish.js
  9. +0 −7 php/3.1/examples/php-push-api-walkthrough-javascript-subscribe.js
  10. +0 −9 php/3.1/examples/php-push-api-walkthrough-php-publish.php
  11. +0 −12 php/3.1/examples/php-push-api-walkthrough-php-subscribe.php
  12. +0 −45 php/3.1/examples/publish-example.php
  13. +0 −47 php/3.1/examples/socket.io-example.php
  14. +0 −44 php/3.1/examples/subscribe-example.php
  15. +0 −157 php/3.1/unit-test.php
  16. +0 −563 php/3.3/Pubnub.php
  17. +0 −94 php/3.3/PubnubAES.php
  18. +0 −211 php/3.3/PubnubTest.php
  19. +0 −32 php/3.3/exitSubOnFalse.php
  20. +0 −13 php/3.3/here_now_example.php
  21. +0 −14 php/3.3/presenceTest.php
  22. +0 −32 php/3.3/pubnub.com.pem
  23. +0 −176 php/3.3/pubnubCipherTextTests.php
  24. +0 −130 php/3.3/pubnubPlaintextTests.php
  25. +0 −13 php/3.3/subscribeTest.php
  26. +0 −563 php/3.4/Pubnub.php
  27. +0 −94 php/3.4/PubnubAES.php
  28. +0 −211 php/3.4/PubnubTest.php
  29. +0 −32 php/3.4/exitSubOnFalse.php
  30. +0 −13 php/3.4/here_now_example.php
  31. +0 −68 php/3.4/noise.php
  32. +0 −51 php/3.4/ping.php
  33. +0 −14 php/3.4/presenceTest.php
  34. +0 −32 php/3.4/pubnub.com.pem
  35. +0 −176 php/3.4/pubnubCipherTextTests.php
  36. +0 −130 php/3.4/pubnubPlaintextTests.php
  37. +0 −13 php/3.4/subscribeTest.php
  38. +2 −98 php/README.md
View
@@ -1,239 +0,0 @@
-<?php
-
-/**
- * PubNub 3.0 Real-time Push Cloud API
- *
- * @author Stephen Blum
- * @package Pubnub
- */
-class Pubnub {
- private $ORIGIN = 'pubsub.pubnub.com';
- private $PUBLISH_KEY = 'demo';
- private $SUBSCRIBE_KEY = 'demo';
- private $SECRET_KEY = false;
- private $SSL = false;
-
- /**
- * Pubnub
- *
- * Init the Pubnub Client API
- *
- * @param string $publish_key required key to send messages.
- * @param string $subscribe_key required key to receive messages.
- * @param string $secret_key optional key to sign messages.
- * @param string $origin optional setting for cloud origin.
- * @param boolean $ssl required for 2048 bit encrypted messages.
- */
- function Pubnub(
- $publish_key = 'demo',
- $subscribe_key = 'demo',
- $secret_key = false,
- $ssl = false,
- $origin = false
- ) {
- $this->PUBLISH_KEY = $publish_key;
- $this->SUBSCRIBE_KEY = $subscribe_key;
- $this->SECRET_KEY = $secret_key;
- $this->SSL = $ssl;
-
- if ($origin) $this->ORIGIN = $origin;
-
- if ($ssl) $this->ORIGIN = 'https://' . $this->ORIGIN;
- else $this->ORIGIN = 'http://' . $this->ORIGIN;
- }
-
- /**
- * Publish
- *
- * Send a message to a channel.
- *
- * @param array $args with channel and message.
- * @return array success information.
- */
- function publish($args) {
- ## Fail if bad input.
- if (!($args['channel'] && $args['message'])) {
- echo('Missing Channel or Message');
- return false;
- }
-
- ## Capture User Input
- $channel = $args['channel'];
- $message = json_encode($args['message']);
-
- ## Generate String to Sign
- $string_to_sign = implode( '/', array(
- $this->PUBLISH_KEY,
- $this->SUBSCRIBE_KEY,
- $this->SECRET_KEY,
- $channel,
- $message
- ) );
-
- ## Sign Message
- $signature = $this->SECRET_KEY ? md5($string_to_sign) : '0';
-
- ## Send Message
- return $this->_request(array(
- 'publish',
- $this->PUBLISH_KEY,
- $this->SUBSCRIBE_KEY,
- $signature,
- $channel,
- '0',
- $message
- ));
- }
-
- /**
- * Subscribe
- *
- * This is BLOCKING.
- * Listen for a message on a channel.
- *
- * @param array $args with channel and message.
- * @return mixed false on fail, array on success.
- */
- function subscribe($args) {
- ## Capture User Input
- $channel = $args['channel'];
- $callback = $args['callback'];
- $timetoken = isset($args['timetoken']) ? $args['timetoken'] : '0';
-
- ## Fail if missing channel
- if (!$channel) {
- echo("Missing Channel.\n");
- return false;
- }
-
- ## Fail if missing callback
- if (!$callback) {
- echo("Missing Callback.\n");
- return false;
- }
-
- ## Begin Recusive Subscribe
- try {
- ## Wait for Message
- $response = $this->_request(array(
- 'subscribe',
- $this->SUBSCRIBE_KEY,
- $channel,
- '0',
- $timetoken
- ));
-
- $messages = $response[0];
- $args['timetoken'] = $response[1];
-
- ## If it was a timeout
- if (!count($messages)) {
- return $this->subscribe($args);
- }
-
- ## Run user Callback and Reconnect if user permits.
- foreach ($messages as $message) {
- if (!$callback($message)) return;
- }
-
- ## Keep Listening.
- return $this->subscribe($args);
- }
- catch (Exception $error) {
- sleep(1);
- return $this->subscribe($args);
- }
- }
-
- /**
- * History
- *
- * Load history from a channel.
- *
- * @param array $args with 'channel' and 'limit'.
- * @return mixed false on fail, array on success.
- */
- function history($args) {
- ## Capture User Input
- $limit = +$args['limit'] ? +$args['limit'] : 10;
- $channel = $args['channel'];
-
- ## Fail if bad input.
- if (!$channel) {
- echo('Missing Channel');
- return false;
- }
-
- ## Get History
- return $this->_request(array(
- 'history',
- $this->SUBSCRIBE_KEY,
- $channel,
- '0',
- $limit
- ));
- }
-
- /**
- * Time
- *
- * Timestamp from PubNub Cloud.
- *
- * @return int timestamp.
- */
- function time() {
- ## Get History
- $response = $this->_request(array(
- 'time',
- '0'
- ));
-
- return $response[0];
- }
-
- /**
- * Request URL
- *
- * @param array $request of url directories.
- * @return array from JSON response.
- */
- private function _request($request) {
- $request = array_map( 'Pubnub::_encode', $request );
- array_unshift( $request, $this->ORIGIN );
-
- $ctx = stream_context_create(array(
- 'http' => array( 'timeout' => 200 )
- ));
-
- return json_decode( @file_get_contents(
- implode( '/', $request ), 0, $ctx
- ), true );
- }
-
- /**
- * Encode
- *
- * @param string $part of url directories.
- * @return string encoded string.
- */
- private static function _encode($part) {
- return implode( '', array_map(
- 'Pubnub::_encode_char', str_split($part)
- ) );
- }
-
- /**
- * Encode Char
- *
- * @param string $char val.
- * @return string encoded char.
- */
- private static function _encode_char($char) {
- if (strpos( ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?', $char ) === false)
- return $char;
- return rawurlencode($char);
- }
-}
-
-
-?>
@@ -1,8 +0,0 @@
-www.pubnub.com - pubnub - realtime push service in the cloud
-
-To start the PHP Chat Client:
------------------------------
- php ./chat-command-line.php PUBLISH-KEY SUBSCRIBE-KEY
-
-Review code in each file to see examples of the PHP Pubnub Client API.
-Publish, Subscribe and History functions are available in the Pubnub PHP Class.
@@ -1,52 +0,0 @@
-<?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":"WeDemo","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)
- ));
-
-?>
@@ -1,68 +0,0 @@
-<?php
-
- ## Capture Publish and Subscribe Keys from Command Line
- $publish_key = isset($argv[1]) ? $argv[1] : false;
- $subscribe_key = isset($argv[2]) ? $argv[2] : false;
-
- # Print usage if missing info.
- if (!($publish_key && $subscribe_key)) {
-echo("
- ==============
- EXAMPLE USAGE:
- ==============
- php ./chat-command-line.php PUBLISH-KEY SUBSCRIBE-KEY
-
-");
- exit();
- }
-
- ## Require Pubnub API
- echo("Connecting...\n");
- echo("(Press ^C to exit)\n");
- 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: ");
- $user = trim(fgets(STDIN));
- $user = $user ? $user : 'chad';
- echo("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");
- }
-
-?>
Oops, something went wrong.

0 comments on commit ebc561a

Please sign in to comment.