trying to figure out how i would tell if a service is running from the watchdog...
[xmppcentral.git] / test / test.php
1 <?php
2
3 // activate full error reporting
4 //error_reporting(E_ALL & E_STRICT);
5
6 include 'XMPPHP/XMPP.php';
7
8 #Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
9 #If this doesn't work, are you running 64-bit PHP with < 5.2.6?
10 $conn = new XMPPHP_XMPP('localhost', 5222, 'radon', 'password', 'xmpphp', 'localhost', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
11 $conn->autoSubscribe();
12
13 try {
14     $conn->connect();
15     while(!$conn->isDisconnected()) {
16         //$payloads = $conn->processUntil();
17         $payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start', 'subscription_requested'));
18         print_r($payloads);
19         foreach($payloads as $event) {
20                 $pl = $event[1];
21                 switch($event[0]) {
22                         case 'message':
23                                 print "---------------------------------------------------------------------------------\n";
24                                 print "Message from: {$pl['from']}\n";
25                                 if($pl['subject']) print "Subject: {$pl['subject']}\n";
26                                 print $pl['body'] . "\n";
27                                 print "---------------------------------------------------------------------------------\n";
28                                 $conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);
29                                 if($pl['body'] == 'quit') $conn->disconnect();
30                                 if($pl['body'] == 'break') $conn->send("</end>");
31                         break;
32                         case 'presence':
33                                 print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
34                         break;
35                         case 'session_start':
36                             print "Session Start\n";
37                                 $conn->getRoster();
38                                 $conn->presence($status="Cheese!");
39                         break;
40                 }
41         }
42     }
43 } catch(XMPPHP_Exception $e) {
44     die($e->getMessage());
45 }
46 ?>