From 78d2f08fcd8014fed1fddcb324560a8f055b0e97 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 5 Jul 2012 16:04:04 -0700 Subject: [PATCH] Add an Aphlict CLI client Summary: Depends on D2926. Adds a simple CLI client for Aphlict to make it easier to debug stuff. Test Plan: Ran client, saw debug messages. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D2927 --- src/docs/userguide/notifications.diviner | 4 ++ .../aphlict/client/aphlict_test_client.php | 72 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100755 support/aphlict/client/aphlict_test_client.php diff --git a/src/docs/userguide/notifications.diviner b/src/docs/userguide/notifications.diviner index f94828c541..0842cf8335 100644 --- a/src/docs/userguide/notifications.diviner +++ b/src/docs/userguide/notifications.diviner @@ -76,6 +76,10 @@ You can run `aphlict` in the foreground to get output to your console: phabricator/ $ ./bin/aphlict --foreground +You can run `support/aphlict/client/aphlict_test_client.php` to connect to the +Aphlict server from the command line. Messages the client receives will be +printed to stdout. + You can set `notification.debug` in your configuration to get additional output in your browser. diff --git a/support/aphlict/client/aphlict_test_client.php b/support/aphlict/client/aphlict_test_client.php new file mode 100755 index 0000000000..7131ef4736 --- /dev/null +++ b/support/aphlict/client/aphlict_test_client.php @@ -0,0 +1,72 @@ +#!/usr/bin/env php +setTagline('test client for Aphlict server'); +$args->setSynopsis(<<parseStandardArguments(); +$args->parse( + array( + array( + 'name' => 'server', + 'param' => 'uri', + 'default' => PhabricatorEnv::getEnvConfig('notification.client-uri'), + 'help' => 'Connect to __uri__ instead of the default server.', + ), + )); +$console = PhutilConsole::getConsole(); + +$errno = null; +$errstr = null; + +$uri = $args->getArg('server'); +$uri = new PhutilURI($uri); +$uri->setProtocol('tcp'); + +$console->writeErr("Connecting...\n"); +$socket = stream_socket_client( + $uri, + $errno, + $errstr); + +if (!$socket) { + $console->writeErr( + "Unable to connect to Aphlict (at '$uri'). Error #{$errno}: {$errstr}"); + exit(1); +} else { + $console->writeErr("Connected.\n"); +} + +$io_channel = new PhutilSocketChannel($socket); +$proto_channel = new PhutilJSONProtocolChannel($io_channel); + +$json = new PhutilJSON(); +while (true) { + $message = $proto_channel->waitForMessage(); + $console->writeOut($json->encodeFormatted($message)); +} +