What is XMPPHP ?

Oct 25, 2013, by admin

Actually XMPPHP is the successor to Class.Jabber.PHP that have been promising for years. Taking advantage of PHP5, it is an elegant solution with a direct approach.  You can directly to Google Talk, LJ Talk, jabber.org, facebook chat by using XMPPHP.

Some of the features include:

Connect to any XMPP 1.0 server (Google Talk, LJ Talk, jabber.org, facebook chat etc)
Supports TLS encryption
Several XML processing approaches and supported styles (process indefinitely, processUntil an event, processTime for a number of seconds), waiting on events or map them, etc.

Examples

A simple code example for sending messages:

  1. <?php
  2. include(“xmpp.php”);
  3. $conn = new XMPP(‘talk.google.com’, 5222, ‘username’, ‘password’, ‘xmpphp’, ‘gmail.com’, $printlog=False, $loglevel=LOGGING_INFO);
  4. $conn->connect();
  5. $conn->processUntil(‘session_start’);
  6. $conn->message(‘someguy@someserver.net’, ‘This is a test message!’);
  7. $conn->disconnect();
  8. ?>

To not use SSL/TLS encryption if available, set

$conn->use_encryption = False;
before calling connect()

A command line bot example:

  1. <?php
  2. include(“xmpp.php”);
  3. $conn = new XMPP(‘talk.google.com’, 5222, ‘user’, ‘password’, ‘xmpphp’, ‘gmail.com’, $printlog=True, $loglevel=LOGGING_INFO);
  4. $conn->connect();
  5. while(!$conn->disconnected) {
  6. $payloads = $conn->processUntil(array(‘message’, ‘presence’, ‘end_stream’, ‘session_start’));
  7. foreach($payloads as $event) {
  8. $pl = $event[1];
  9. switch($event[0]) {
  10. case ‘message’:
  11. print “———————————————————————————n”;
  12. print “Message from: {$pl[‘from’]}n”;
  13. if($pl[‘subject’]) print “Subject: {$pl[‘subject’]}n”;
  14. print $pl[‘body’] . “n”;
  15. print “———————————————————————————n”;
  16. $conn->message($pl[‘from’], $body=“Thanks for sending me ”{$pl[‘body’]}”.”, $type=$pl[‘type’]);
  17. if($pl[‘body’] == ‘quit’) $conn->disconnect();
  18. if($pl[‘body’] == ‘break’) $conn->send(“</end>”);
  19. break;
  20. case ‘presence’:
  21. print “Presence: {$pl[‘from’]} [{$pl[‘show’]}] {$pl[‘status’]}n”;
  22. break;
  23. case ‘session_start’:
  24. $conn->presence($status=“Cheese!”);
  25. break;
  26. }
  27. }
  28. }
  29. ?>

Hope you all like the post to get more updates like the page Bugtreat Technologies to know about our latest templates like the page Cs Cart Templates