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.
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:
root@ubuntu:~/git# cd JAXL
root@ubuntu:~/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_BIN_PATH to configure installation paths.
Issue following commands to setup Jaxl library core and Jaxl command line utility:
root@ubuntu:~/git/JAXL# mkdir /usr/share/php/jaxl
root@ubuntu:~/git/JAXL# ./build.sh install
uninstalling old package...
root@ubuntu:~/git/JAXL# touch /var/log/jaxl.log
root@ubuntu:~/git/JAXL# chown www-data /var/log/jaxl.log
root@ubuntu:~/git/JAXL# touch /var/run/jaxl.pid
root@ubuntu:~/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.
Now that we have setup Jaxl on our system, lets verify package installation by firing jaxl command line utility on the terminal:
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
// Connecting jabber server details
Now run the echobot from using jaxl cli utility:
root@ubuntu:/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:
root@ubuntu:~/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