Introducing JAXL – Open Source Jabber XMPP Library

Introduction

JAXL stands for “Jabber XMPP Library“. For fun, it stands for “Just Another XMPP Library

This library currently supports following features:

  • Connect to a Jabber Server (e.g. Gtalk)
  • TLS Encryption
  • DIGEST-MD5 and PLAIN authentication mechanisms
  • Roster Support

Library comes with the following class files:

  1. config.ini.php : Holds your jabber account and mysql connection information
  2. mysql.class.php : Basic MySQL connection class used to insert received messages and presence into MySQL database
  3. logger.class.php : A very basic logger class which allows you to log all XML stanza’s send and received from jabber server
  4. xmpp.class.php : Base XMPP class library which implements the XMPP protocol
  5. jaxl.class.php : JAXL class which extends XMPP class library. Should be the starting point for your application.
  6. index.php : After building your application in jaxl.class.php, you finally initializa and call your methods here

Source Code
JAXL is hosted at Google Code. Checkout full source code from here:
http://code.google.com/p/jaxl

Google Groups
jaxl
Visit this group

How to use JAXL:
JAXL Client Library is highly structured. There is a base XMPP class library (xmpp.class.php) and a JAXL class library (jaxl.class.php) which is derived from the base XMPP class library.

Base XMPP class library implements the XMPP protocol and it also provides you with two extendable methods named eventMessage() and eventPresence(). These methods are internally called when a message or presence XML Stanza is received from the Jabber server.

Jaxl.class.php must be the starting point for all your applications. Simply customize the eventMessage() and eventPresence() Method for your application. Other methods which might interest you while customizing them are:

  1. sendMessage($jid,$message) : For sending message to a particular Jid
  2. sendStatus() : To set your status message
  3. roster(‘get’) : To get list of roster
  4. roster(‘add’,$jid) : Add a new contact in roster list
  5. roster(‘remove’,$jid) : Remove a contact from roster list
  6. roster(‘update’,$jid,$name,$groups) : Update a particular contact in roster
  7. subscribe($jid) : Subscribe for presence of a particular $jid

This library includes the following files:

Config File (config.ini.php)
You specify all your jabber account username and password in this file. For development environment keep $env = “devel” and for production simply change it to $env = “prod”

  // Set an enviornment
  $env = "prod";

  // Log Level for logger class
  $logEnable = TRUE;

  // Log in MySQL database
  $logDB = FALSE;

  $key = array("prod"=>array("user"=>"myproductionuser",
                             "pass"=>"password",
                             "host"=>"talk.google.com",
                             "port"=>5222,
                             "domain"=>"gmail.com"
                            ),
              "devel"=>array("user"=>"mydevelopmentuser",
                             "pass"=>"password",
                             "host"=>"localhost",
                             "port"=>5222,
                             "domain"=>"localhost"
                            )
              );

  $db = array("prod"=>array("dbuser"=>"root",
                            "dbpass"=>"password",
                            "dbhost"=>"localhost",
                            "dbname"=>"jaxl"
                           ),
             "devel"=>array("dbuser"=>"root",
                            "dbpass"=>"password",
                            "dbhost"=>"localhost",
                            "dbname"=>"jaxl"
                           )
             );


MySQL Class (mysql.class.php)
This is a basic MySQL connection class used to insert received messages and presence into MySQL database

Base XMPP Class (xmpp.class.php)
You should not worry about this class. Until and unless you are aware of what are you trying to achieve you should not touch this class file.

Logger Class (logger.class.php)
This is a basic logger class. It help you log XML send to and received from jabber server. Might prove helpful in debugging and if you are interested in learning the core of XMPP Protocol.

Extended JAXL Class (jaxl.class.php)
You will be customizing eventMessage() and eventPresence() methods here.

    function eventMessage($fromJid, $content, $offline = FALSE) {
      if($offline) {
        $this->sendMessage($fromJid,"Hi, Thanks for your offline message");
      }
      else {
        $this->sendMessage($fromJid,"Hi, Thanks for your message");
      }

      if($this->logDB) {
        // Save the message in the database
        $timestamp = date('Y-m-d H:i:s');
        $query = "INSERT INTO message (FromJid,Message,Timestamp) value ('$fromJid','$content','$timestamp')";
        $this->mysql->setData($query);
      }
    }

    function eventPresence($fromJid, $status, $photo) {
      // Change your status message to your friend's status
      $this->sendStatus($status);

      if($this->logDB) {
        // Save the presence in the database
        $timestamp = date('Y-m-d H:i:s');
        $query = "INSERT INTO presence (FromJid,Status,Timestamp) value ('$fromJid','$status','$timestamp')";
        $this->mysql->setData($query);
      }
    }

In above example I have done 4 things:

  • Sends back a message saying “Hi, Thanks for your offline message”, when I receive a offliner.
  • Sends back a message saying “Hi, Thanks for your message”, when I receive an IM from my friend.
  • Change my status message, as and when I receive a status update from my friends.
  • Save messages and presence into database if $logDB = TRUE in config.ini.php

Final Call (index.php)

  /* Include Key file */
  include_once("config.ini.php");

  /* Include JAXL Class */
  include_once("jaxl.class.php");

  /* Create an instance of XMPP Class */
  $jaxl = new JAXL($key[$env]['host'],    // Jabber Server Hostname
                   $key[$env]['port'],    // Jabber Server Port
                   $key[$env]['user'],    // Jabber User
                   $key[$env]['pass'],    // Jabber Password
                   $key[$env]['domain'],  // Jabber Domain
                   $db[$env]['dbhost'],   // MySQL DB Host
                   $db[$env]['dbname'],   // MySQL DB Name
                   $db[$env]['dbuser'],   // MySQL DB User
                   $db[$env]['dbpass'],   // MySQL DB Pass
                   $logEnable,            // Enable Logging
                   $logDB                 // Enable MySQL Inserts
                  );

  try {
    /* Initiate the connection */
    $jaxl->connect();

    /* Communicate with Jabber Server */
    while($jaxl->isConnected) {
      $jaxl->getXML();
    }
  }
  catch(Exception $e) {
    die($e->getMessage());
  }

Instant Messenger Powered by JAXL
I am pleased to announce 3 months after release of JAXL, 1st Instant Messenger powered by JAXL. Currently the instant messenger is in testing phase and will be released after some 3-4 weeks of thorough testing. Meanwhile here is the first clip shot:

Disclaimer
Currently this library is being developed and used at Gtalkbots.com . Though it is thoroughly tested and being used, I still recommend not to use it on production servers. Mainly, since it is heavily customized for Gtalkbot’s usage. I am releasing it, as I see it of use for the community worldwide. If you want to use it, use at your own risk. Let me know of any changes you make to this library. In future I look to make this library more generic.

Enjoy and let me know of any bugs, feedbacks, enhancements or any abuse you may want to pass through if it doesn’t work for you 😛

You should be running index.php using command line and not browser (recommended). This class is currently highly customized for Gtalkbots usage and works perfectly with Gtalk Servers.

  • Pingback: Behind the scenes - How and What XML’s are exchanged by JAXL | Abhi's Weblog()

  • x1311

    Hi there,
    very interesting Library. What I am mostly interested in is how eventMessage() gets called internally. Could you describe the whole message flow with core components?

  • Yeah in the case study of google talk server http://abhinavsingh.com/blog/2009/01/behind-the-scenes-how-and-what-xmls-are-exchanged-by-jaxl/, i did missed the XML stanza’s being transmitted when a message is sent or received.

    Here is what JAXL receives when a message is sent:

    <message to=”[email protected]” type=”chat” id=”325″ from=”[email protected]/Talk.v104233E14DB”><body>Hi dood</body><active xmlns=”http://jabber.org/protocol/chatstates”/><nos:x value=”disabled” xmlns:nos=”google:nosave”/><arc:record otr=”false” xmlns:arc=”http://jabber.org/protocol/archive”/></message>

    So you can see that along with incoming XML, Gtalk server also tells you about the features supported by Gtalk server.

    Here is what you will receive for an offline message:

    <message to=”[email protected]” from=”[email protected]”><body>Hi dood</body><x stamp=”20090104T16:27:25″ xmlns=”jabber:x:delay”/><time ms=”1231086445192″ xmlns=”google:timestamp”/></message>

    Hence from the incoming XML stream, you know that it’s an off liner.

    I hope this is what you asked for. See the example jaxl.class.php where I have handled both online and offline messages separately.

    Enjoy.

  • x1311

    Ok, thank you. I´ll take a deeper look.

  • x1311

    I was just wondering how you could receive the incoming messages. I did not code php for a long time. But I just found the streams in the documentation 🙂

  • Yeah when you connect to gtalk server JAXL will log each incoming and outgoing streams in logger.log file under /log directory. Simply set $logEnable = TRUE in config.ini.php.

  • namespace

    Hey, First of all thanks for such a great library. There are many available in PHP, but JAXL is one of the best documented library for me.

  • Hi Abhi

    Many thanks for sharing your excellent work with all. We are newbies trying to code a chatbot and your library is very helpful. I have two off-topic comments to make:

    1. The wordpress theme and especially its name is great. 🙂
    2. How are these geometric image avatars generated for commenters on your blog?

    Regards
    Vinayak  

  • Thanks Vinayak. I would love to list your application on Jaxl’s google code page. Kindly let me know when you are done with your application.

    About the theme name, well that was my nick name back in college, so tried playing with that.

    About the Geometric Image Avatars, well they are generated by Gravatar. Nothing to do with my theme or code.

    Do lemme know about your application and all the best 🙂

  • Gaurav

    Hi

    I am trying to learn how to create gtalk powered bots. I want to create a bot that translates words from english to hindi. For example, if you send the word “One” the bot should reply back with “ek”. For this purpose I have created a php script that takes a word as input, looks up in a database and returns an output.

    Now I want to connect this php script to the bot. I have also created an account on gmail to act as a bot [[email protected]].

    My question is that now how do I connect this php script to the gmail bot? What is the role of Jaxl in this? My understanding of the process is this:

    1. User sends keyword through gtalk to gmail jabber server
    2. Gmail jabber server sends the message to [email protected]il.com
    3. dictionaribot… transmits the keyword to the php script
    4. the php script looks up keyword in mysql database and returns a value
    5. the value is transmitted to the user through the jabber server.

    My confusion is as to how is information transferred in steps 3 and 5 above. how is the connection between the gtalk message and the php script is made?

    I am sorry if the question is stupid but I am a beginner and trying to just enter into this field.

    Thanks,
    Gaurav

  • Hi Gaurav,

    No worries, we all start from basic. What you want to achieve is quite straight forward if you are using JAXL. I hope by now u understand how to make use of JAXL.

    For your application you simply need to customize the eventMessage() method in jaxl.class.php.

    From my guess it will look like this:
    <code>
    function eventMessage() {
    if(!$offline) {
    // Grab the sentence passed by the user
    $sentence = trim($content);
    // Now simply lookup in your database or use google language api’s to convert this sentence to hindi
    $translatedSentence = database_lookup($content);
    // If you wish acknowledge JAXL library
    $translatedSentence .= “npowered by Jaxl http://code.google.com/p/jaxln“;
    // Finally send back the translated sentence
    $this->sendMessage($fromJid,$translatedSentence);    
    }
    }
    </code>

    You simply have to replace the database_lookup function with your application code.  (For more idea see the source code of jaxl4dzone.class.php)

    However I guess there is already some bots released by Google themselves for such translations.

    All the best! Do lemme know when you are done with your application, I will list that on the Jaxl google code page 🙂

  • Gaurav

    Hi Abhinav

    Thanks for the prompt reply. I would request you to be a little patient with me on this.

    I have understood the way to handle the operations once the message is recd by the php file.

    However, I am confused as to how to send messages received on the [email protected] id to the index.php file on my web server.

    Right now this is what is happening:

    [email protected] > [email protected]

    But for the bot to work, what should happen is:

    [email protected] > [email protected]>index.php>mySQL>index.php>[email protected] > [email protected]

    How does one transmit info from the jabber id to the php file?

    Thanks in advance for your support.

  • Gaurav

    To clarify the above message – how do I initiate the execution of the index.php page? It is lying on my XAMPP web server. Should I create a cron job that executes index.php after a set period of time.

  • I guess the following workflow will help you:

    • [email protected] sends a message saying “One” to [email protected]
    • [email protected] receives it as $content and $fromJid contains email id of the sender
    • Now you will have to do one of the following things: (i) Either you create a class out of your index.php file and then include it in jaxl.class.php. Then send “One” to this class from within eventMessage() method and receive “ek” (ii) Put the whole index.php logic inside eventMessage() method, so that you translate $content inside eventMessage() method itself, before sending it back to $fromJid
    • There is no problem with querying database inside eventMessage() method.

    Simply set $logDb = TRUE in config.ini.php and then change the $query inside jaxl.class.php to what ever query you want to. Get back the required translation from the database and send it back to the user.

    I hope this shd definitely get you going. All the best.
    PS: No need of any cron job or any other trick.

  • Gaurav

    Sorry to bother you again. But the place where I am still confused is quoted below:
    <quote>
    send “One” to this class from within eventMessage() method and receive “ek”
    </quote>

    How this will happen both are separate containers?

    Thanks in advance

  • I guess u need to just read a little about OOPS. You can very well make a class out of your application which queries the database and gets the translated data. Then include this class in jaxl.class.php, create a new object. Pass $content using this object to your application class and get back the translated results in the jaxl.class.php itself. 🙂

    I guess give a lill fight and u will get thr. All the best, leaving for party 🙂

  • Vinayak

    Hi

    I have been reading with interest the discussion between Abhi and Gaurav. Abhi – I think the continued confusion is because the problem is not clear and you are offering the solution for the wrong problem. I made a diagram showing the process and the part where gaurav is facing a problem.

    Take a look: http://i41.tinypic.com/24vl6x5.jpg

    The problem I think lies in part 2 of the process. While Abhi is telling the solution for part 3 and 4, which I think Gaurav has worked out using Jaxl.

    Gaurav, pls confirm my understanding.

  • Well I m not sure how could I hve made a similar diagram, but here is the flow diagram which I would like to present.

    » User’s PC 
    » User logon to Gtalk messenger 
    » Open up [email protected] for translation 
    » Type in “One” in the chat window and press enter 
    » This message goes to Gtalk Jabber Servers, who sees that User is trying to send this message to [email protected] and redirects that message to [email protected] 
    » [email protected] is running as a bot on gaurav’s php server
    » The message is received by eventMessage() method inside JAXL class
    » Now inside this class, gaurav receives this status message as $content and then Gaurav’s code will fire a SQL query to the database from within eventMessage() method. It will be something like this. $query = “SELECT hindi_translation where english_word = ‘One'”;
    » Gaurav’s code will receive the returned $resultset, and now gaurav will send back this translated message to User using $this->sendMessage()
    » This message will again first go to Gtalk server which will redirect this message to the intended user.

    I am not sure if this is what you are looking for from me. However I wish you will be able to get that working now 🙂

    All the best!

    PS: I have uploaded this image on tinyurl so that it doesn’t vanish for future readers 🙂

  • Gaurav

    Yes I agree with Vinayak. Now there is only 1 doubt left i.e.

    how to get the bot running on the server?

    More specifically, please refer to this line of your explanation:
    » [email protected] is running as a bot on gaurav’s php server

    I tried executing the index.php file and got this warning:

    Warning: fwrite(): supplied argument is not a valid stream resource in /home/iilvin/public_html/dictionari/jaxl/xmpp.class.php on line 152


    I am also copy pasting Log file entries:
    Log file entries:

    2009-01-15 03:25:02
    Initializing class variables

    2009-01-15 03:25:02
    Trying to connect at talk.google.com:5222

    2009-01-15 03:25:23
    Failed to establish a connection at talk.google.com:5222

    2009-01-15 03:25:23
    Sending XML>>
    </stream:stream>

    Thanks

  • [email protected] is running as a bot on gaurav’s php server

    This part means that on your server, you have started the bot using command line. More specifically this means you have issued the following command php index.php in the directory where JAXL recides and it has started successfully.

    I am also copy pasting Log file entries”
    Well looking at the log enteries and the warning which you got, I guess you are on a shared hosting and you are for some reasons not allowed to open a TCP connection. Do check with your host provider if a PHP command like fsockopen, stream_set_blocking, stream_set_timeout is allowed for you. If unfortunately the answer is NO, you can’t run JAXL on your server. Infact none of the XMPP library will be able to run successfully.
  • Gaurav

    Thanks Abhi
    I’ll contact the host provider.

  • For all further discussions I would encourage you to join the JAXL google group, and take part in on-going discussions.

    Thanks in advance,
    Abhinav
  • Hi Gaurav,

    Did you get a chance to enquire about the permissions set by your hosting provider? Are you allowed to issue socket programming commands in PHP on your host.
    Thanks,
    Abhinav
  • Gaurav

    Hi Abhi,

    The delay has been because the hosting provider had an elaborate mechanism for granting permission for shell access. We got the permission to run commans through commandline yesterday only.

    Now when I login I get the following response:

    log: Initializing class variables
    log: Trying to connect at talk.google.com:5222
    log: Failed to establish a connection at talk.google.com:5222
    log: Sending XML>>
    </stream:stream>
    Warning:  fwrite(): supplied argument is not a valid stream resource in /home/iilvin/public_html/dictionari/jaxl/xmpp.class.php on line 152

    It seems we need to specifically ask permission for running the commands that you mentioned. I am raising a ticket for the same today. Will keep you informed of the progress.

  • Gaurav

    Hi Abhi,

    I got this reply from my hosting provider:

    Commands allowed: “fsockopen”, “stream_set_blocking”
    Commands not allowed: “stream_set_timeout”

    Pls suggest me if there is any workaround to the command – stream_set_timeout.

    Or if you could suggest a web host that supports all the required configurations. Where are you hosting your site?

    Regards

  • well i doubt you can go ahead with this hosting then. Well I have my own virtual private server so I have full control on my server. You may want to try x10hosting.com. I used it when I started web development, though I am not sure if you have these commands allowed there again.

    However this shd work perfectly on your local system, coz you won’t have any restrictions set thr.
    All the best
  • Gaurav

    Hi Abhi,

    I am planning to go for my own virtual private server. Vendors are asking for server configration. Pls suggest if the configration below is fine or any changes are required?

    Disk Space: 10 GB
    Monthly Bandwidth Transfer: 100 GB
    cPanel Version: 10.x or above
    Apache Version: 2.2.x (Unix)
    PHP Version: 5.2.8
    MySQL version: 5.x or above
    Architecture: x86_64
    Operating System: Linux [which flavor would you suggest?]
    RAM: 2GB

  • Gaurav it depends on your need and how much resources you will be needing. I guess you can go ahead with the above configuration of disk space and ram. But I didn’t get why did you mentioned the PHP, Apache and MySQL versions. That is all in your hand and you will need to configure yourself, unless your VPS hosting provider is giving you pre-configured VPS…. 

    I personally use debian as OS. So if you want you can go ahead with the same. If you get Ubuntu, you can get that too, its similar to ubunut.
  • i want anagrams games bot…
    can i get the coding.. for that…

  • Anyhow i am working with jaxl library..  to create an anagram games bot like gtalkbots.com … I am not a hardcore programmer So i dont know the % of success … if that gtalkbots anagram code  is an open source then i need hardly need that code… Thank You for Developing Such an good jaxl Library..

  • Thanks Yuva….Well the plan if ofcourse to release that too. I have already released a few sample applications and target is to keep producing more sample applications which can show the power of JAXL and XMPP Protocol.

    However the code was written about 6 months back in a hurry and is not so well structured. Need to restructure the same, before I release it for other developers. Don’t want to churn out a bad practice code in public 😉
  • I have Contacted You By Mail

  • Gaurav

    Hi Abhi

    I now have access to a VPS with LAMP.  I was able to get the dictionaribot working finally using JAXL. 🙂

    Next I installed a jabber server (jabberd) and tried to create an account using the Exodus chat client installed on my local windows machine. However I got this error:
    <code>
    Looking up SRV: _xmpp-client._tcp.iilv.in
    Got A: 67.223.233.252  5222
    SENT: <stream:stream to=”iilv.in” xmlns=”jabber:client” xmlns:stream=”http://etherx.jabber.org/streams”  xml:lang=”en” version=”1.0″ >
    RECV: <?xml version=’1.0′?><stream:stream xmlns:stream=’http://etherx.jabber.org/streams’ id=’49919FC7′ xmlns=’jabber:client’ from=’iilv.in’>
    SENT: <iq id=”jcl_2″ type=”get”><query xmlns=”jabber:iq:auth”><username>abcd</username></query></iq>
    RECV: <stream:error>Disconnected</stream:error></stream:stream>
    </code>

    Can you help me with this?

    Many thanks in advance.

  • Hi Gaurav,

    First of all congratulations on your bot. I would ask you to kindly let me know your bot email-id so that I can list it on the code.google pages of JAXL.
    Further, you can create a new account in ejabberd using the admin panel directly. You don’t need any chat client for that. I am not sure what this error is, probably can investigate later and let you know. As of now you can open the admin panel of ejabberd and create user account from there.

    A quick google search gives me this, probably this can be of some help:
    http://www.google.co.in/search?hl=en&rlz=1C1GGLS_enIN291IN304&q=Looking+up+SRV:+_xmpp-client.&btnG=Search&meta=

    Regards,
    Abhi
    PS: Do let me know your bot email-id
  • Pingback: Programatically control your google mails using JAXL v 1.0.4 | Abhi's Weblog()

  • Gaurav

    Hi Abhi

    The bot is not functional as yet. We are still struggling with a few issues. I will let you know all the details once we get it going. Many thanks for your ongoing help and interest.

    There are 2 main issues that we face:

    1. We are running the php file by logging on to our VPS through the console provided by PuTTY which is a free telnet and SSH Client for Windows and Unix platforms.  But as soon as I close the PuTTY executable on my local machine, the bot goes offline on the VPS.

    2. Can JAXL work with non-gmail bots? Can I host my own bot?

    Thanks
    Gaurav

  • Hello, i need to add a jabber web client to my wordpress web page but my emplyer dont want to use the wordpress plugin. I`m trying to use the JAXL library but when i set up the config file, i get this error
    <failure xmlns=’urn:ietf:params:xml:ns:xmpp-sasl’>
    <not-authorized/>
    </failure>
    I add a new test user to my jabber server (I`m using EjabberD) and double check the username and password.
    Any idea?
    Thanks in advance

  • Hi,

    Strange enough. BTW can you confirm if you have updated your username and password under the right enviornment, i.e. probably you have added ur username and password under dev enviornment and you have $env = “prod” set.

    Also can you kindly send in the complete logs till you get the above error for more debugging.

  • Vinayak

    Hi Abhi

    In your anagram bot, how do you remember the user’s state? For example if you have sent him a jumbled word and he asks for a hint, how do you know which word’s hint should be sent. Because at any time, a number of users must be chatting with the bot. And each user could be on a different word.

    Do you create some session or something? Or do you store and retrieve values in a db?

    Thanks in advance

  • You got it wrong actually. At any point in time, all users are trying to answer the same jumbled word. The one who answers first (and believe me the difference is in micro seconds) wins the round.

    However if you plan to keep a user session independent of each other, than you need to maintain a session on server side, which will contain information on user basis. 
    Getting this from Db is not at all recommended. Best is to use memcache. Read this post of mine on how to use memcache. http://abhinavsingh.com/blog/2009/01/memcached-and-n-things-you-can-do-with-it/
  • Pingback: How to broadcast a message to your Gtalk friends using JAXL? | Abhi's Weblog()

  • Pankaj

    Hi, I have a debian server. I was using jaxl library but now i am using xmpphp library for bot development as i have to use bosh .
    Is there any provision of bosh under jaxl library?

    When i create a bot using xmpphp library i.e through xmpp file its working fine but when i try to use bosh it generates a fatal error.

    Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’ in /var/www/testlib/XMPPHP/BOSH.php:75 Stack trace:

    0 /var/www/testlib/XMPPHP/BOSH.php(75): SimpleXMLElement->__construct(”)

    1 /var/www/testlib/index.php(14): XMPPHP_BOSH->connect(‘myserver’)

    2 {main} thrown in /var/www/testlib/XMPPHP/BOSH.php on line 75

    Can you Please help me on this?

    Thanks
    Pankaj

  • As far as I know, XMPPHP is not fully bosh compatible. It provides you a kind of backend code for bosh implementation, but for clubbing that with browser you need to write your own wrappers.

    Bosh support is already present in JAXL, though not released yet. I am planning to release that by mid next month. (busy with other commitments)
    Reason why I build JAXL after initially using XMPPHP was, I found XMPPHP was having memory leakage. Try running your bot for a week and you will find the bot will die out with memory exception. On JAXL, i haven’t seen any memory outage as of now 😀
    BTW why did you moved to XMPPHP from JAXL, any specific reasons?

  • Pankaj

    Hi,
    Thanks for your prompt reply.
    My main reason of moving out to xmpphp was bosh support specifically for state remembrance/session maintenance .

    Regards,
    Pankaj

  • Yup, indeed. You may try your luck with xmpphp till JAXL releases bosh library extension. 😀 

    All the best.
  • Pingback: 5 exciting (gaming) bots you can create using Jaxl (Jabber XMPP Library) in PHP | Abhi's Weblog()

  • Pankaj

    Hi Abhi,
    Thanks for your cooperation regarding our queries.
    I want to know whether its possible to implement pubsub functionality in jaxl, if its possible then how?
    My scenario is : user subscribes to an event & when an event occurs message is sent to all the subscribers.
    I have debian server with openfire.
    Can you please help me on this?
    Thanks,
    Pankaj
     
     

  • I guess you are referring to http://xmpp.org/extensions/xep-0060.html as pubsub right? Well unfortunately thats not a part of Jaxl yet, but seriously I want to have that in Jaxl soon.

    However if you want to simulate pubsub model using current Jaxl library, here is how you can go ahead (never tested or tried, but i guess should work. No idea how scalable it will be).

    1. Create a master bot say with jid: [email protected]
    2. You can code the eventMessage() method for the master bot in such a way that on receiving a particular message say “subscribe”, master bot will subscribe the sender jid. You can write through to backing store like MySQL.
    3. Further events that occur can again be captured by customizing eventMessage() and eventPresence() functions. You will need to tweak them in a way so that they are triggered for all possible event types. For e.g. You capture the event, “Whenever [email protected] changes his status” and as soon as you capture this inside eventPresence() you broadcast the required details to all subscribed users.

    For scalability you might want to use memcached or other such distributed caches. Lemme know if you make any progress on this, you can release that as jaxl4pubsub.class.php 😀

  • Pankaj

    Hi Abhi,
    Thanks for your reply i will try pubsub functionality later on as i am facing a critical issue.
    Actually my bot goes offline very frequently. I have already applied the ping method as stated by some users. I have also checked the log file but could not found out the reason for it. Then i checked  nohup.out file . It contains
    Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages:
    error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry in /var/www/bot/xmpp.class.php on line 153
    May be this is causing some problem?
    One more thing my debian server is having 256 MB RAM whereas openfire config file has this setting:
    DAEMON_OPTS=”-Xms256m -Xmx512m”
    i.e. memory limit from 256-512
    May be this is also the reason ? I am little bit confused whether less memory of my server is causing some issue or the error in the nohup.out is causing memory leakage?
    Can you please guide me on this?
    Thanks,
    Pankaj
     
     

     
     

  • A quick google search tells me that this might be a PHP bug itself. See this http://bugs.php.net/bug.php?id=40993&edit=1. Well in such a case you might have to consider upgradation of PHP .

    What PHP version do you have? I have PHP 5.2.0-8 and face no such issues.

  • Pankaj

    Hi Abhi,
    I have php version 5.2.6-1+lenny2. One more thing  i would like to know whether its due to this error my bots are going offline or less memory of server causing this issue.
    Please help.
    Thanks
    Pankaj
     

  • I am not sure, but yes this can be a reason. After how much time does the bot go offline. Best will be to do some sort of profiling of the bot you have written so that you exactly get to know the problem. Try xdebug.

  • Pankaj

    Thanks Abhi for replying there is no such fixed time frame for my bots getting offline. Sometimes in two days its getting offline. Yesterday i have reststarted the bot but today its offline again. May be low memory of server causing this as yesterday while testing on openfire server i checked that when java memory reached above 250 mb the server hanged then i have to restart the server.
    It would be a great help if you can provide me a link how to use xdebug. I have no idea about it.
    Thanks,
    Pankaj
     
     

  • Xav

    Hi,
     
    Any idea if I could use sendMessage to send message to other networks?my jabber server has some gateways installed and most accounts have a Yahoo! account associated with them, though if I use sendMessage with a $jid for yahoo.com the request never works.
    Have you tried this by any chance?
    Thanks,
    xav

  • Hi Xav,

    Yes you can send messages across the networks too, but then you will need to have s2s configured i.e. server to server configs. I haven’t played around much with these but if you see the jabber config file you will get an idea. Yahoo, MSN, IRC integration are possible though that will require some configs.

    All the best.

  • Doublet

    When does your own webclient comes opensourced?

  • Hi Doublet,

    I am currently working on memchat. Delay in Jaxl based webclient is happening because I am moving the javascript FE part to jQuery. (initially i coded using plaing javascript).

    Also another reason is the time limits at my end. I will appreciate if a couple of interested developers can step in and help me completing this project.

    Regards.

  • Hi Abhinav Singh,

    Thanks for providing such wonderful Libraby.
    i have a simple doubte… how can i disconnect from gtalk using JAXl…
    i dont find any disconnect functions…

    can u plz help me…….

  • Hi abhi,
    i have trying jaxl to communicate with my local jabber server.
    jaxl is successfully connected with my server, but failed when starting TLS encryption, it’s indicated some problrm with my stream_socket_enable_crypto() function, please give me your solution.

    are your eventMessage() could handle jabber conference chat?

    thank for your nice library 🙂

  • aeyel

    hi i need a chat solution for my php site.would this solution work with open fire?

    • Hi Aeyel,

      Jaxl is well tested with gtalk, ejabberd and openfire. Should be fine, though beware Jaxl is not for browser based chat apps still.

  • Ashley

    Hi, does Jaxl work in PHP 4 or only PHP 5?

    • Hi Ashley,

      Well i haven’t tried running on PHP4. Probably you can try and let me know if you encounter any problem. Will be eager to fix them up. (I never planned to run it on php4 myself and hence never bothered to check it on php4)

  • danielrve

    Hi!! do you release the instant messenger?? how can I download?

    Great Work!!

    Regards

    • Hi,

      I am onto it almost full time since past 1 week. I can’t assure a date, but expect a wp plugin by mid month.

      Similar to the one you see below on my blog.

  • where can i find this command line…??

    Run from command line:

    1. [email protected]:/jaxl$ sudo php index.php
    2. OSType: Linux, Registering shutdown for SIGINT and SIGTERM
    3. OpenSSL: Enabled for CLI
    4. Attempting DIGEST-MD5 Authentication…
    5. Starting Session…
    6. Requesting Feature List…
    7. Requesting Roster List…
    8. Setting Status…
    9. Done

  • ildar, russia

    Hi! thanks for this library! i’ve some q’s, can you help me, plese? – i wanna use jaxl in my intranet jabber server – Openfire 3.6 + MySQL – can i get the result whith it? I just plan to send messages on some alerts to different users and thats all 🙂
    Thanks!

  • ravi

    is this also working with openfire server. I tried to connect xmpphp based client but it show http-bind 404 error.
    so help me please

  • Hi Ravi,

    Yes jaxl do work well with openfire too. I remember my days of experimenting with xmpphp arnd 2 yr back and i couldn’t make it work back then.

  • ravi

    hi ……
    thanks for reply.
    Actually i am new in php. I tried to connect jaxl to openfire but only long loading process is shown on browser.
    Because i want to know how it will connect so i did not include mysql.clas.php file and remove the variable related to it. But it is not working.
    index.php code is this:-

    connect();
    echo ‘4’;
    /* Communicate with Jabber Server */
    while($jaxl->isConnected) {
    $jaxl->getXML();
    echo ‘5’;
    }

  • ravi

    code :

    connect();

    /* Communicate with Jabber Server */
    while($jaxl->isConnected) {
    $jaxl->getXML();
    }
    }
    catch(Exception $e) {
    die($e->getMessage());
    }

  • ravi

    /*

    connect();

    /* Communicate with Jabber Server */
    while($jaxl->isConnected) {
    $jaxl->getXML();
    }
    }
    catch(Exception $e) {
    die($e->getMessage());
    }
    */

  • ravi

    //1 connect();
    //20 echo ‘4’;
    //21 /* Communicate with Jabber Server */
    //22 while($jaxl->isConnected) {
    //23 $jaxl->getXML();
    //24 echo ‘5’;
    //25 }
    “index.php” 32L, 706C

  • ravi

    is jaxl with openfire support multiuser chatting.

  • Current Jaxl version do not support connection from the browser. You can only run bots from command line.

    Jaxl support for browsers will be released soon with next major version release.

  • Pingback: May 20th | Matthieu Bozec()

  • Somya

    When will the multi user chat be supported in jaxl library?

    thanks.

  • Hi Somya,

    Multi-user chat support already exists. Kindly chk Jaxl v 2.0 release blogs and documentation. http://github.com/abhinavsingh/JAXL

  • Seif

    Hey, i only know objective-c and i want to make a chat app for the iphone.

    Please tell me what i need to learn.
    I know XMPP, but do i need to know PHP/mySQL?

    What else, how do i have a server? please tell me in details.
    Thanks.
    Seif.

    • Hi Seif,

      You can start with installing ejabberd server on your host. Thereafter checkout the development version of Jaxl library and run the sample examples (7 in total) that comes packaged with the library.

      Ofcourse you will need to know some PHP to work with Jaxl library.

  • Hi Brother
    Firstly thanks for this library…
    I am totally new to XMPP. I want to built a chat application for my website. I have installed OPENFIRE XMPP server. So will this library help me to connect to this server and will i be able to make my own ONE TO ONE chat system on my website using this library.. please reply..

    Thanks

    • Hi Dhiraj,

      Library will do all that you want plus a lot more if you need to.
      Checkout the latest from github https://github.com/abhinavsingh/jaxl and run sample examples under /app folder.
      They have been tested against a number of jabber servers including Openfire.

  • Thanks brother…

    just one more botheration. where i can get full documentation of this new library of yours….

  • Bro i m getting this error during connection in my error console.

    Uncaught TypeError: Cannot read property ‘length’ of null
    jaxl.handlePayloadjaxl.js:129
    $.ajax.successjaxl.js:122

  • I have solved above problem But now JSON response is

    [{“jaxl”:”curlError”,”code”:7,”msg”:”couldn’t connect to host”}]

    although i have enabled curl in my server..

    Log Message:

    [1:5460:0] 2011-03-01 13:53:55 – [[XMPPSend]] body

    [1:5460:0] 2011-03-01 13:53:56 – [[JAXL0124]] Curl errno 7 encountered. Failed to connect with http://localhost:5280/http-bind/

  • FULL LOG with level 5

    [1:5460:0] 2011-03-01 15:55:20 – [[JAXL]] No callbacks for shutdown

    [1:5460:0] 2011-03-01 15:55:20 – [[JaxlAction]] connect
    {“user”:”admin”,”pass”:”admin”,”jaxl”:”connect”,”PHPSESSID”:”4qasd6d61rlr8h8oljo0reto72″}

    [1:5460:0] 2011-03-01 15:55:20 – [[JAXL0124]] Loading session data
    {“uid”:11,”user_name”:”admin”,”gid”:”(1,2)”,”pid”:1,”csv_array”:{“headers”:[“Campaign Name”,”Date Sent”,”Comments”,”Sent To”,”Sent”,”Pending”,”Error”],”1″:[“Test”,”Mar 1 2011 12:00AM”,” “,100,0,100,0]},”jaxl_auth”:”connect”,”jaxl_sid”:”ea6d65a4″,”jaxl_rid”:2406}

    [1:5460:0] 2011-03-01 15:55:20 – [[JAXL]] Calling JAXL0206 method startStream

    [1:5460:0] 2011-03-01 15:55:20 – [[JAXL0124]] Not authed yet, Not commiting session
    {“uid”:11,”user_name”:”admin”,”gid”:”(1,2)”,”pid”:1,”csv_array”:{“headers”:[“Campaign Name”,”Date Sent”,”Comments”,”Sent To”,”Sent”,”Pending”,”Error”],”1″:[“Test”,”Mar 1 2011 12:00AM”,” “,100,0,100,0]},”jaxl_auth”:”connect”,”jaxl_sid”:”ea6d65a4″,”jaxl_rid”:2406}

    [1:5460:0] 2011-03-01 15:55:20 – [[XMPPSend]] body

    [1:5460:0] 2011-03-01 15:55:21 – [[JAXL]] Calling JAXL0206 method out

    [1:5460:0] 2011-03-01 15:55:21 – [[JAXL0124]] Curl errno 7 encountered. Failed to connect with http://localhost:5280/http-bind/

    [1:5460:0] 2011-03-01 15:55:21 – [[BoshOut]]
    [{“jaxl”:”curlError”,”code”:7,”msg”:”couldn’t connect to host”}]

  • mehdi

    Hello,

    Where can we get the instant messenger that you’ve built?

    Thank you in advance.

    Best,
    Mehdi

  • pvenugopal

    how we come to know the class provider of the urn:Xmpp:archive.please help me iam strugling a lot

  • pablo

    my question is how do I disconnect from the command line?.
    whether to connect index.php launched out of the server as I can do

  • Parth

    Hi Abhishek,

    I have a big and long term project .On that I need to implement chat module .
    That may be one to one or multiuser .

    To achieve this I have installed Openfire as xmpp server and xmpphp as client to connect with openfire .This is working fine . Now I want to create and delete users from openfire using xmpphp .Users are creating but not able to delete the users . Each time I am getting internal server error though following the xmpp guideline .This is frustating me and looking for an alternate .
    After some searching I found about JAXL .
    Before moving to JAXL , could you give me
    pros and cons of JAXL over xmpphp .

    Thanks and Regards
    Parth

  • Vivek Shingala

    Hi, Abhi…

    This is such a great library to connect with jabber server. I’ve seen many comments and many articles of jaxl and tried code in my localhost using php. But its not working.

    So I want to know that only XAMPP is enough for this to work, or I need some other configuration to work with??

    Could you please provide step by step procedure for sendMessage example on windows OS??

    I run that example file in my command prompt(windows) like,

    C:xampphtdocsjaxl-1.0.4>php sendMessage.php [email protected] hi

    but it returns the error like below,

    ‘php’ is not recognized as an internal or external command,
    operable program or batch file.

    I don’t understand this problem, please help me for this.

    Thanks

    • parth

      Hi Vivek,
      The error is clearly stating that php is not a windows command .
      Since PHP is a third party software, to execute php as a command ,you need have 2 options.

      1. go to the directory where php is installed (in you case c:/xampp/php)

      2. make the php installation path as global command path by setting it in environment variables . To do this append your php path in the path setting of environment variables under system properties .

      Thanks
      Parth

  • Vivek Shingala

    Thanx Parth…
    Problem solved…!!

  • Announcing Jaxl v3.x – asynchronous, non-blocking I/O, event based PHP client/server library – http://abhinavsingh.com/blog/2012/07/announcing-jaxl-v3-x-asynchronous-non-blocking-io-event-based-php-clientserver-library/