Skip to content

Instantly share code, notes, and snippets.

@pgl
Last active August 29, 2015 14:01
Show Gist options
  • Save pgl/28bb140dbb8802b6da70 to your computer and use it in GitHub Desktop.
Save pgl/28bb140dbb8802b6da70 to your computer and use it in GitHub Desktop.
Pubnub test script
#!/usr/bin/php
<?php
/*
* CLI test script
*
* Call as:
*
* publishtest.php
* publishtest.php "uncompressed message" 0
* publishtest.php "compression test" 1 # gzip compress msg when publishing
*/
require_once './Pubnub.php';
// $conf can easily be replaced with an ini file
// eg: $conf = parse_ini_file('pubnub.ini');
$conf = [
'pubnub.channel' => 'my_channel',
'pubnub.pub_key' => 'demo',
'pubnub.sub_key' => 'demo',
];
$msg = $argv[1] ?: 'test';
$compress = $argv[2] ?: false;
$pubnub = new Pubnub($conf['pubnub.pub_key'], $conf['pubnub.sub_key'], $compress);
if ($compress) {
echo "using compression\n";
}
$return = $pubnub->publish([
'channel' => $conf['pubnub.channel'],
'message' => [ 'test message' => $msg ],
'compress' => $compress,
]);
print_r($return);
@pgl
Copy link
Author

pgl commented May 13, 2014

One liner:

php -r 'require "./Pubnub.php"; print_r((new Pubnub("demo"))->publish(["channel" => "my_channel", "message" => $argv[1]]));' "my message"

@stephenlb
Copy link

TY!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment