How to perform X-FACEBOOK-PLATFORM and Google Talk X-OAUTH2 XMPP authentication with PHP Jaxl library

Ever since Jaxl library first introduced support for X-FACEBOOK-PLATFORM XMPP authentication mechanism, it has changed significantly. Also, Google Talk now supports OAuth 2.0 Authorization, an XMPP extension to allow users to log in using OAuth 2.0 credentials. Both these mechanisms are a big win for XMPP developers, since real-time conversation experience can now be provided to their application users without asking them for their passwords. In this blog post, I will demonstrate how to perform X-FACEBOOK-PLATFORM and X-OAUTH2 XMPP authentication mechanism using Jaxl v3.x PHP Library. X-FACEBOOK-PLATFORM XMPP Authentication Here is a quick guide on how to perform X-FACEBOOK-PLATFORM XMPP authentication using xfacebook_platform_client.php which comes bundled with Jaxl v3.x examples: Visit Facebook Developer Apps page and register your application Once registered, visit access token tool to get required parameters to perform X-FACEBOOK-PLATFORM authentication Click on the debug button next to […]

Read More

JAXLXml – Strophe style XML Builder : Working with Jaxl – A Networking Library in PHP – Part 2

Prior to Jaxl v3.x, the most ugliest piece of code inside Jaxl library was handling of XML packets. If you are working with XMPP protocol which is all about sending and receiving XML packets, it can become a nightmare if you don’t have a proper XML manipulation library in your toolkit. For Jaxl v3.x, first thing I decided to write was JAXLXml class, which is a custom XML packet implementation with no external dependencies and is an extension over the ideas from Strophe.Builder class written by Jack Moffitt. JAXLXml is generic enough to find a place inside any PHP application that requires easy and elegant XML packet creation. In this blog post, I will give an exhaustive overview of how to create XML packets using JAXLXml class. JAXLXml Constructor Depending upon the need, there are several different ways of initializing […]

Read More

Working with Jaxl – A Networking Library in PHP – Part 1 – An Introduction, Philosophy and History

Development of Jaxl library started way back in December’07 while I was working on a self-initiated project called Gtalkbots. The project is now dead, if you are interested in knowing more about it go through Gtalkbots BlogSpot. Jaxl v1.x was first released in Jan’09 and about a year later in Aug’10 Jaxl v2.x was released. First two versions were released as JAbber XMPP Library for writing clients and external server components. While working on my startup Jaxl – A Platform As A Service (PAAS) for developing real-time applications, I started experiencing v2.x limitations when my external server side components were unable to process XMPP packets at the speed they were sent by ejabberd server. I started restructuring and refactoring the library which gave birth to Jaxl v3.x. Since v3.x was initially being used for developing the entire infrastructure, it shaped […]

Read More

Announcing Jaxl v3.x – asynchronous, non-blocking I/O, event based PHP client/server library

Jaxl v3.x is a successor of v2.x (and is NOT backward compatible), carrying a lot of code from v2.x while throwing away the ugly parts. A lot of components have been re-written keeping in mind the feedback from the developer community over the last 4 years. Also Jaxl shares a few philosophies from my experience with erlang and python languages. Jaxl is an asynchronous, non-blocking I/O, event based PHP library for writing custom TCP/IP client and server implementations. From it’s previous versions, library inherits a full blown stable support for XMPP protocol stack. In v3.0, support for HTTP protocol stack was also added. At the heart of every protocol stack sits a Core stack. It contains all the building blocks for everything that we aim to do with Jaxl library. Both XMPP and HTTP protocol stacks are written on top […]

Read More

PHP Code, Setup and Demo of Jaxl boshchat application

Jaxl 2.0 bosh support allow web developers to write real time web applications within minutes, without having any pre-requisite knowledge about the XMPP protocol itself. In this blog post, I will walk you through setup and demo of an XMPP based web chat application using Jaxl library. Get the code Follow the following steps to download and install this sample web application on your systems: Clone the development branch of Jaxl library root@ubuntu:~/git# git clone git@github.com:abhinavsingh/JAXL.git root@ubuntu:~/git# cd JAXL/ root@ubuntu:~/git/JAXL# If you are not familiar with git, simply visit JAXL@github, click Download Source and extract under ~/git/JAXL directory on your system Once inside Jaxl source directory, build the latest development package root@ubuntu:~/git/JAXL# ./build.sh building… Install Jaxl library (view installation detail and options) root@ubuntu:~/git/JAXL# ./build.sh install uninstalling old package… installing… Setup web chat application Jaxl library is default installed under /usr/share/php/jaxl […]

Read More

Releasing Jaxl 2.0 – Object oriented XMPP framework in PHP

After months of restructuring the Jaxl library, I am pleased to announce Jaxl 2.0, an object oriented XMPP framework in PHP for developing real time applications for browsers, desktops and hand held devices. What’s new in Jaxl 2.0? A lot of structural changes has been done from the previous version to make it more scalable, robust, flexible and easy to use Library now provides an event mechanism, allowing developers to register callbacks for various xmpp events in their application code Use integrated BOSH support to write real time web applications in minutes More than 10 new implemented XMPP extensions (XEP’s) added Development hosting moves to github, stable releases available at google code Documentation for Jaxl users Below is a list of getting started documentation for XMPP app developers: Installation, Usage guide and Sample applications Jaxl Core classes, available methods and […]

Read More

MEMQ : Fast queue implementation using Memcached and PHP only

Memcached is a scalable caching solution developed by Danga interactive. One can do a lot of cool things using memcached including spam control, online-offline detection of users, building scalable web services. In this post, I will demonstrate and explain how to implement fast scalable queues in PHP. MEMQ: Overview Every queue is uniquely identified by it’s name. Let’s consider a queue named “foo” and see how MEMQ will implement it inside memcached: Two keys namely, foo_head and foo_tail contains meta information about the queue While queuing, item is saved in key foo_1234, where 1234 is the current value of key foo_tail While de-queuing, item saved in key foo_123 is returned, where 123 is the current value of key foo_head Value of keys foo_head and foo_tail start with 1 and gets incremented on every pop and push operation respectively Value of […]

Read More

How to use locks in PHP cron jobs to avoid cron overlaps

Cron jobs are hidden building blocks for most of the websites. They are generally used to process/aggregate data in the background. However as a website starts to grow and there is gigabytes of data to be processed by every cron job, chances are that our cron jobs might overlap and possibly corrupt our data. In this blog post, I will demonstrate how can we avoid such overlaps by using simple locking techniques. I will also discuss a few edge cases we need to consider while using locks to avoid overlap. Cron job helper class Here is a helper class (cron.helper.php) which will help us avoiding cron job overlaps. (See usage example below) <?php define(‘LOCK_DIR’, ‘/Users/sabhinav/Workspace/cronHelper/’); define(‘LOCK_SUFFIX’, ‘.lock’); class cronHelper { private static $pid; function __construct() {} function __clone() {} private static function isrunning() { $pids = explode(PHP_EOL, `ps -e | […]

Read More

How to add content verification using hmac in PHP

Many times a requirement arises where we are supposed to expose an API for intended users, who can use these API endpoints to GET/POST data on our servers. But how do we verify that only the intended users are using these API’s and not any hacker or attacker. In this blog post, I will show you the most elegant way of adding content verification using hash_hmac (Hash-based Message Authentication Code) in PHP. This will allow us to restrict possible misuse of our API by simply issuing an API key for intended users. Here are the steps for adding content verification using hmac in PHP: Issue $private_key and $public_key for users allowed to post data using our API. You can use the method similar to one described here for generating public and private keys. Users having these keys can now use […]

Read More

PHP tokens and opcodes : 3 useful extensions for understanding the working of Zend Engine

“PHP tokens and opcodes” – When a PHP script is executed it goes through a number of processes, before the final result is displayed. These processes are namely: Lexing, Parsing, Compiling and Executing. In this blog post, I will walk you through all these processes with a sample example. In the end I will list some useful PHP extensions, which can be used to analyze results of every intermediate process. Lets take a sample PHP script as an example: <?php function increment($a) { return $a+1; } $a = 3; $b = increment($a); echo $b; ?> Try running this script through command line: ~ sabhinav$ php -r debug.php 4 This PHP script goes through the following processes before outputting the result: Lexing: The php code inside debug.php is converted into tokens Parsing: During this stage, tokens are processed to derive at […]

Read More