Skip to content

Commit 78d2f08

Browse files
author
epriestley
committedJul 5, 2012
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
1 parent 63be89b commit 78d2f08

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
 

‎src/docs/userguide/notifications.diviner

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ You can run `aphlict` in the foreground to get output to your console:
7676

7777
phabricator/ $ ./bin/aphlict --foreground
7878

79+
You can run `support/aphlict/client/aphlict_test_client.php` to connect to the
80+
Aphlict server from the command line. Messages the client receives will be
81+
printed to stdout.
82+
7983
You can set `notification.debug` in your configuration to get additional
8084
output in your browser.
8185

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* Copyright 2012 Facebook, Inc.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
$root = dirname(dirname(dirname(dirname(__FILE__))));
21+
require_once $root.'/scripts/__init_script__.php';
22+
23+
$args = new PhutilArgumentParser($argv);
24+
$args->setTagline('test client for Aphlict server');
25+
$args->setSynopsis(<<<EOHELP
26+
**aphlict_test_client.php** [__options__]
27+
Connect to the Aphlict server configured in the Phabricator config.
28+
29+
EOHELP
30+
);
31+
$args->parseStandardArguments();
32+
$args->parse(
33+
array(
34+
array(
35+
'name' => 'server',
36+
'param' => 'uri',
37+
'default' => PhabricatorEnv::getEnvConfig('notification.client-uri'),
38+
'help' => 'Connect to __uri__ instead of the default server.',
39+
),
40+
));
41+
$console = PhutilConsole::getConsole();
42+
43+
$errno = null;
44+
$errstr = null;
45+
46+
$uri = $args->getArg('server');
47+
$uri = new PhutilURI($uri);
48+
$uri->setProtocol('tcp');
49+
50+
$console->writeErr("Connecting...\n");
51+
$socket = stream_socket_client(
52+
$uri,
53+
$errno,
54+
$errstr);
55+
56+
if (!$socket) {
57+
$console->writeErr(
58+
"Unable to connect to Aphlict (at '$uri'). Error #{$errno}: {$errstr}");
59+
exit(1);
60+
} else {
61+
$console->writeErr("Connected.\n");
62+
}
63+
64+
$io_channel = new PhutilSocketChannel($socket);
65+
$proto_channel = new PhutilJSONProtocolChannel($io_channel);
66+
67+
$json = new PhutilJSON();
68+
while (true) {
69+
$message = $proto_channel->waitForMessage();
70+
$console->writeOut($json->encodeFormatted($message));
71+
}
72+

0 commit comments

Comments
 (0)
Failed to load comments.