Jaxl 2.0 – Installation, Usage guide and Example apps

This blog post provides detailed instructions on how to download and setup Jaxl 2.0 for quick XMPP application development using PHP. We will also see how to run XMPP bots using Jaxl command line utility (now available by just typing jaxl on the terminal).

Get the source code
Jaxl 2.0 development version source code is available at github.

  • For better experience download latest stable tarball from google code
  • The development version of Jaxl is hosted here at Github, have fun cloning the source code with Git. If you are not familar with Git just use the download button to get a tarball.
    [email protected]:~/git# git clone git://github.com/abhinavsingh/JAXL.git

Warning: the development source code is only intended for people that want to develop Jaxl or absolutely need the latest features still not available on the stable releases.

Installation on *nix Systems
Extract the downloaded tarball and enter source directory. The available build.sh file will help us installing Jaxl library at a preferred location on our system. Type ./build.sh help to view help instructions:

[email protected]:~/git# cd JAXL
[email protected]:~/git/JAXL# ./build.sh help

Build file will default install Jaxl library core under /usr/share/php/jaxl and Jaxl command line at /usr/bin/jaxl. Open build script, edit PACKAGE_INSTALL_PATH and PACKAGE_BIN_PATH to configure installation paths.

Issue following commands to setup Jaxl library core and Jaxl command line utility:

[email protected]:~/git/JAXL# mkdir /usr/share/php/jaxl
[email protected]:~/git/JAXL# ./build.sh
building...
[email protected]:~/git/JAXL# ./build.sh install
uninstalling old package...
installing...
[email protected]:~/git/JAXL# touch /var/log/jaxl.log
[email protected]:~/git/JAXL# chown www-data /var/log/jaxl.log
[email protected]:~/git/JAXL# touch /var/run/jaxl.pid
[email protected]:~/git/JAXL# chown www-data /var/run/jaxl.pid

/var/log/jaxl.log is default log file for Jaxl applications and /var/run/jaxl.pid saves the process id (pid) of running Jaxl instances.

Usage guide
Now that we have setup Jaxl on our system, lets verify package installation by firing jaxl command line utility on the terminal:

[email protected]:~/git/JAXL# jaxl
Missing ini file...

If you get “Missing ini file” message, you have successfully verified package installation. This message is shown when current working directory doesn’t have jaxl.ini file, which is required by Jaxl cli utility before it can connects to a jabber server.

Running sample applications
Build script installs a sample application under /usr/share/php/jaxl/app/echobot directory. This directory contains two files namely:

  • echobot.php: Contains our echobot application code
  • jaxl.ini: It is application specific Jaxl configuration file

Open and update the following section inside jaxl.ini:

        // Connecting bot details
        define('JAXL_USER_NAME', 'username');
        define('JAXL_USER_PASS', 'password');

        // Connecting jabber server details
        define('JAXL_HOST_NAME', 'jabber.org');
        define('JAXL_HOST_PORT', 5222);
        define('JAXL_HOST_DOMAIN', 'jabber.org');

Now run the echobot from using jaxl cli utility:

[email protected]:/usr/share/php/jaxl/app/echobot# jaxl echobot.php
== 2946 == [[2010-08-02 14:37:53]] Socket opened to the jabber host jabber.org:5222 ...
== 2946 == [[2010-08-02 14:37:57]] Performing Auth type: DIGEST-MD5
== 2946 == [[2010-08-02 14:38:02]] Auth completed...

2946 is the process id of current running Jaxl instance. Same value can be found inside /var/run/jaxl.pid. Also tail the Jaxl log file for debug information:

[email protected]:~/git/JAXL# tail -f /var/log/jaxl.log
== 2946 == [[2010-08-02 14:38:02]] [[XMPPSend]] 123
chatOnline using Jaxl (Jabber XMPP Library in PHP)1

[[XMPPSend]] tells us that following XMPP packet was send by the Jaxl instance running with pid 2946. Also, total 123 bytes were transmitted over the socket.

Proceed to Writing your first command line bot using Jaxl for detailed explanation of the sample echobot application or if you are interested in building real-time web applications read Setup and Demo of Jaxl boshchat application

  • Pingback: Releasing Jaxl 2.0 – Object oriented XMPP framework in PHP | Abhi's Weblog()

  • Pingback: Writing a command line XMPP bot (echobot) using Jaxl 2.0 | Abhi's Weblog()

  • Pingback: Jaxl 2.0 Core classes, available methods and directory structure | Abhi's Weblog()

  • Pingback: Facebook chat connect with X-FACEBOOK-PLATFORM using Jaxl 2.0 | Abhi's Weblog()

  • Pingback: PHP Code, Setup and Demo of Jaxl boshchat application | Abhi's Weblog()

  • Pingback: XEP 0045 – Multi User Chat (MUC) available methods in Jaxl 2.0 | Abhi's Weblog()

  • Pingback: How to write External Jabber Components in PHP using Jaxl library? | Abhi's Weblog()

  • Absa

    Hi Abhinav,

    Can you write down steps to setup JAXL on a Windows server?

    Thanks,
    A

  • Hi Absa,

    Surely some developers have already requested for the same. I am planning for a post this coming weekend, explaining JAXL setup on windows server.

  • Absa

    That would be awesome 🙂 I look forward to that post.

  • aka

    i dont understand this jaxl platform, I mean there is not finish application that i can use and test to see how it’s work and learn from it?
    i mean some application that works?

  • Hi Aka,

    Was that a joke? 😉 Seriously you can find 4 working example: echobot (command line application), component bot (cli app) and 2 Bosh applications (one for peer-2-peer chat and another for MUC chat) under downloaded /app folder…

    Here is a direct link.. http://github.com/abhinavsingh/JAXL/tree/master//app/ Do let me know if you face any difficulty in getting started with Jaxl

  • aka

    sorry for the dump question but i upload everything to the server by the FTP, I entered to the apps and nothing you can see: http://akamaor.com/test/jaxl/app/
    do I need to do something else that it will work to edit something?

  • Hi Aka,

    You need to go through a bunch of tutorials (http://code.google.com/p/jaxl/#Documentation_for_Jaxl_Users) before you can get any of them started…

    /app directory contains 4 sample application in respective sub-directories. Documentations will help you with how to set them up and run on your own servers…

  • aka

    look I tried this guide http://abhinavsingh.com/blog/2010/08/facebook-chat-connect-with-x-facebook-platform-using-jaxl-2-0/ several times in diffrents ways and I dont understand what am i doing wrong that it ain’t works:S
    sorry I’m bother you =

  • Hi Aka,

    Kindly join the group http://groups.google.com/group/jaxl where other developers can help you out with specific problems…

    I am not sure how you are trying to implement Jaxl on your system? What is your system configuration? What are the exact steps that you followed? What do you see inside jaxl.log, which can probably help us debug your problem in detail.

    Every single example application works out on linux/windows, you probably are missing out the basic clue somewhere… 🙂

  • Hello All,

    Kindly follow these steps for running jaxl library on a windows box http://code.google.com/p/jaxl/issues/detail?id=19&can=1

  • prem

    Dear abi,
    I have installed ejabber in my system.

    When i run the echobot to make my id online always .

    I have configured the jaxl.ini file in echobot.Still my id not becomes online in my jabber server.When i login the same id in jabber client like gajim or kopete.Then the id becomes login in my ejabber server.

    Below are the messages displayed when i run the ejabber server.

    jaxl echobot.php
    [7479] 2010-12-31 14:47:46 – Registering shutdown for SIGH Terms …
    [7479] 2010-12-31 14:47:46 – Openssl enabled …
    [7479] 2010-12-31 14:47:46 – Socket opened to the jabber host matrimony.net:5222 …

    Thank you,

    With Regards,
    Prem

  • Richard Robertson

    Sigh. Yet another client. I’m trying to set up a XMPP chat HOST. I’m using a web hosting site. I do not have shell access. I cannot run the chat system as a background process. I had my site hosting company open the necessary ports already. I can do the latest PHP and Perl programs, scripted or pre-compiled. I’m working with a private group with sensitive data and I can’t go through a third party host. Obviously submitting any such website for “pre-approval” is out of the question. Is there any use I can get out of your library for such a project?

    • Hi Richard,

      Using Jaxl for web based chat applications doesn’t require you to run any background process. All you need is a web server and jabber server.
      Checkout boshchat.php sample application and see if you can get this working on your host.

    • Hi Richard,

      Kindly let me know the domain you want to run chat widget upon and we can work out a possible solution for it. 🙂

  • Hi I m trying to setup jaxl on windows but i don’t find any help for that. The link u mention is broken.
    Kindly explain in easy steps.
    Thanks

  • Vikas

    I am looking to do SRV DNS lookup using JAXL library? It does not do that by default? Any help!?

    • Hi Vikas,

      You can use Net_DNS package from PEAR repository. Since it is not supported on windows, i didn’t made it as a dependency inside Jaxl core.
      However it should be easy to use & integrate that if you want to.

  • Vlad

    Guys,
    I have a big problem, very very frustrating.

    I keep getting this error when I try to run the example from above:
    Fatal error: Call to undefined function jaxl_require() in /usr/local/lib/php/jaxl/core/jaxl.class.php on line 41

    I installed the Jaxl on my linux dedicated several times… but I stilll get this error.

    Can anyone help?

    Thanks,
    Vlad

    • Hi Vlad,

      Can you try and fetch the latest Jaxl lib from github and let me know if works fine for you?

  • Vlad

    HEllo,
    IT seems that the latest version fixed that problem, but now, I am receiving this:
    [[XMPP]] Unable to open socket to the jabber host

    I am sure this is not a Jaxl problem, but any idea what I can do to fix it?

    Thanks,
    Vlad

  • Maize

    How to install without .sh? 🙁

    • Hi Maize,

      Download/extract and include v 2.1.2-rc1 which removes build.sh dependency. Kindly let me know how it goes.

  • JooJar

    Abhinav,

    Whilst I thank you for the library you’ve developed the documentation, and instructions are a little poor.

    There is no build.sh in the latest release, so people following this tutorial like myself are left hanging until you respond to us. Please update your blog as to why there is no build.sh and what we should do to install it.

    • Hi JooJar,

      Jaxl v 2.1.2-rc1 removes build.sh from distribution. Users should now simply download/extract/include and start writing XMPP applications now.
      I will soon move entire documentation to http://jaxl.net and remove all duplicate references on my blog to help new users.

  • Matt

    Do i need to install the new version anyhow?

    I downloaded your package, extracted it to some location on my server, edited echobot.php with correct gtalk info and ran echobot.php in my browser.

    I only get a blank page there.
    Am I doing something wrong?

  • Hafiz

    Hope this is not spam here :

    Hi Abhinav, already test your v2.1.2… Is this just can run on localhost? Can’t run on web hosting? I’m using PHP5 too and test your code more than 5 hours just now and nothing I got for possible run FB Chat… 🙁

    I think your guide not complete or not update. Hope you can make a new post and telling how to & step by step about new version…

    I already test your old version too, and seriously I got nothing here… And I don’t know this is the truth code can use FB Chat or not… Still try and try but now very stuck just focus on your code…

  • Alex

    hi, i get the error in error log when the application is installed to my fb profile

    Stack trace:
    #0 /home/domain/public_html/jaxl/app/echobot.php(19): JAXL->__construct(Array)
    #1 {main}
    thrown in /home/domain/public_html/jaxl/core/jaxl.class.php on line 695
    [25-Mar-2011 09:51:17] PHP Warning: touch(): Unable to create file /var/run/jaxl.pid because Permission denied in /home/domain/public_html/jaxl/core/jaxl.class.php on line 695
    [25-Mar-2011 09:51:17] PHP Fatal error: Uncaught exception ‘JAXLException’ with message ‘Pid file /var/run/jaxl.pid doesn’t exists’ in /home/domain/public_html/jaxl/core/jaxl.class.php:695
    Stack trace:

    how to fix this? :

    • You simply need to create jaxl.pid file at desired location.

  • Nil

    Hi,

    I am using JAXL 2.1.1. I have installed it following the procedure described in the blog above. I then tried the echobot.php for getting online presence information from facebook. However, the program is getting halted after the following steps:

    [[email protected] echobot]# jaxl echobot.php
    [5477] 2011-04-02 06:17:24 – Registering shutdown for SIGH Terms …
    [5477] 2011-04-02 06:17:24 – Openssl enabled …
    [5477] 2011-04-02 06:17:24 – Socket opened to the jabber host chat.facebook.com:5222 …

    Could anyone please tell me what’s going wrong here? I have tried this also for gtalk server and the result is same. Thanks in advance.

    The content of the corresponding /var/log/jaxl.log is as follows:

    [5472] 2011-04-02 06:16:23 – Jaxl stream not connected to jabber host, unable to send xmpp payload…

    [5477] 2011-04-02 06:17:24 – [[XMPPSend]] 185

    [5477] 2011-04-02 06:17:25 – [[XMPPGet]]
    X-FACEBOOK-PLATFORMDIGEST-MD5

    [5477] 2011-04-02 06:17:25 – [[XMPPSend]] 51

    [5477] 2011-04-02 06:17:26 – [[XMPPGet]]

    [5477] 2011-04-02 06:17:38 – [[XMPPSend]] 16

    The jaxl.ini is as follows:

  • Nil

    Not sure why message got truncated – probably there’s a limit on the size of a post. Anyhow, if any body has any suggestion on the above issue please let me know and if required I can send them my jaxl.ini and jaxl.log for review.

    Thanks,
    Nil.

  • Nitro

    Abhinav,

    Jaxl is good project, but It should be OS platform-independent and user should not be exposed to compile project. I’m tried run one of the example codes and I’m obtain some errors, look:

    Warning: touch() [function.touch]: Unable to create file /var/log/jaxl.log because No such file or directory in C:daneserwerhtdocsxmppcorejaxl.class.php on line 692

    Fatal error: Uncaught exception ‘JAXLException’ with message ‘Log file /var/log/jaxl.log doesn’t exists’ in C:daneserwerhtdocsxmppcorejaxl.class.php:692 Stack trace: #0 C:daneserwerhtdocsxmppappsendMessage.php(26): JAXL->__construct(Array) #1 {main} thrown in C:daneserwerhtdocsxmppcorejaxl.class.php on line 692

    • i think these are minor errors which user should obviously be able to solve looking at the log content.
      However a future release will target to throw more user understandable error/warning to ease out first experience with library.

  • Nitro

    I have Windows 7 with XAMPP Server. I try with Jaxl send message. I set correct value in app/sendMessage.php. I set correct path for Log and Pid Path [what do you need it?] in core/jaxl.class.php [maybe it’s not the best way], refresh page and … nothing happens, I not receive any messages.

    So what do I do?

  • suneesh

    Abhinav,

    Using jaxl we are able to create and delete users in ejabberd server. But now we moved to tigase server as xmpp server, add and delete now not working. We are getting SASL authentification error. When i changed authType’=>’PLAIN’
    script hanging up…what we do? whether we are able to create users in tigase server using jaxl?

  • Hi Abhinav,

    A dumb question. I used to host my bots on Imified.com. Now that the site is closing down, I need to create my own bots. Jaxl looks promising to me.

    Can you guide me how to start and read a level where a user can interact directly with my bot in Gtalk??

    Thanks,
    Himanshu

  • suneesh

    hi Abhinav,

    whether Jaxl will work with Tigase server?

    • Jaxl lib actually doesn’t know what is it talking to… as far as it’s all XMPP, jaxl should work with Tigase too..

  • 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/