PHP

Writing a custom unix style tail in PHP using Libevent API on Mac OS X 10.5.x and other platforms

Posted on

Libevent is a library which provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Many famous applications/frameworks/libraries like memcached are using libevent. In this blog post, I will demonstrate how to write a custom unix style tail script using Libevent API in PHP. Setting up the environment: Setting up libevent with PHP is a little tricky. Below are the steps, I followed to make it work on Mac OSX 10.5. However the steps should be same for any other OS you choose to code on. […]

PHP

Web Security : Using crumbs to protect your PHP API (Ajax) call from Cross-site request forgery (CSRF/XSRF) and other vulnerabilities

Posted on

Have your API calls ever being used directly by someone without your permission? If yes, read on to find out how can we protect our API’s from such spammers and hackers. Before we go ahead and see a possible solution for this, lets try to list out a few cases, when our API’s can be accessed without our permissions. Common cases of vulnerable API/Ajax calls Ajax calls having no user authentication: This is the first place where a spammer will try to find out a loop hole. Take this example, suppose I created a group chat plugin for my blog. […]

PHP

Building a Custom PHP Framework with a custom template caching engine using Output Control functions

Posted on

In past 1 year or so, I had opportunities of using a lot of php frameworks including zend, symfony, cakephp, codeigniter. All frameworks have their pros and cons, however that is out of scope of this blog post. You may want to checkout this comparison list of php frameworks here. In this blog post I will build a custom PHP framework (MVC Architecture). Then go on to discuss in brief about the output control functions and finally show how to build a custom template caching engine using these functions for our framework. Source Code You may want to download the […]

PHP

XML Parsing in PHP, XPATH way – The best I know so far

Posted on

If you are a PHP developer, you surely must have done XML parsing at some stage or the other. Over the years I myself have implemented XML Parsing in atleast 3-4 different ways. Finally I have stuck to this approach which I personally find far more better than the rest, Not only because it’s quite simple but also because it’s extendable. By extendable I mean, you don’t have to touch your code if the XML structure changes at a later stage or if you need to parse a new node at a later stage in the project. In this blog […]

PHP

Facebook type image rotation and more using PHP and Javascript

Posted on

If you are a facebook geek like me, you must have noticed till now the image rotate functionality in the photo albums. Facebook allows you to rotate images 90 degree clockwise and anti-clockwise after image upload. If you haven’t tried that till now, below is a screenshot for your convenience. Question: But the question is how does facebook team succeed doing this in one click. Today I tried looking around for a solution over internet and I came across the inbuilt imagerotate functionality in PHP. Problem: Unfortunately the problem is that even if you have GD Library extension enabled in […]

PHP

MySQL Query Cache, WP-Cache, APC, Memcache – What to choose

Posted on

Hello Cache Freaks, Ever since I changed my job (from Business Intelligence to Web development) and started working with my present employer, I have had a chance to work on a lot of scalable projects. From making my project to scale from 20 Million PV’s to 100 Million PV’s to development of an internal tool, the answer to all scalable applications have been caching. There are a lot of caching techniques which are being employed by sites worldwide. WP-Cache used in wordpress – a file system based caching mechanism APC Cache – an opcode based caching system Memcache – an […]

Open Source

Behind the scenes – How and What XML’s are exchanged by JAXL

Posted on

Pre-requisite Though it’s not mandatory but will be helpful if you have given a casual reading to the following RFC’s: Extensible Messaging and Presence Protocol(XMPP):Core Extensible Messaging and Presence Protocol(XMPP):Instant Messaging and Presence Case Study: Google Talk Server JAXL Sends >> <!–?xml version=”1.0″?–> <stream:stream xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0” xmlns=“jabber:client” to=“gmail.com” xml:lang=“en” xmlns:xml=“http://www.w3.org/XML/1998/namespace”></stream:stream> Gtalk Acknowledges With >> <!–?xml version=”1.0″ encoding=”UTF-8″?–> <stream:stream from=“gmail.com” id=“981E0522D7363BDF” version=“1.0” xmlns:stream=“http://etherx.jabber.org/streams” xmlns=“jabber:client”> <stream:features>   <starttls xmlns=“urn:ietf:params:xml:ns:xmpp-tls”>     <required>   </required></starttls>   <mechanisms xmlns=“urn:ietf:params:xml:ns:xmpp-sasl”>     <mechanism>X-GOOGLE-TOKEN</mechanism>   </mechanisms> </stream:features></stream:stream> JAXL Sends >> <starttls xmlns=“urn:ietf:params:xml:ns:xmpp-tls”></starttls> Gtalk Acknowledges With >> <proceed xmlns=“urn:ietf:params:xml:ns:xmpp-tls”></proceed> JAXL Sends >> <!–?xml version=”1.0″?–> <stream:stream xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0” xmlns=“jabber:client” to=“gmail.com” xml:lang=“en” xmlns:xml=“http://www.w3.org/XML/1998/namespace”></stream:stream> Gtalk Acknowledges With >> <!–?xml version=”1.0″ encoding=”UTF-8″?–> <stream:stream from=“gmail.com” id=“C01610C43D6A37A2” version=“1.0” xmlns:stream=“http://etherx.jabber.org/streams” xmlns=“jabber:client”> <stream:features>   <mechanisms xmlns=“urn:ietf:params:xml:ns:xmpp-sasl”>     <mechanism>PLAIN</mechanism>     <mechanism>X-GOOGLE-TOKEN</mechanism>   </mechanisms> </stream:features></stream:stream> JAXL Sends >> <auth xmlns=“urn:ietf:params:xml:ns:xmpp-sasl” mechanism=“PLAIN”>AGFjY192nbRbm3J1cGvxYWRzAG15QVRNcGlukT9zcpMxAjI=</auth> Gtalk Acknowledge With >> <success xmlns=“urn:ietf:params:xml:ns:xmpp-sasl”></success> JAXL Sends >> <!–?xml version=”1.0″?–> <stream:stream xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0” xmlns=“jabber:client” to=“gmail.com” xml:lang=“en” xmlns:xml=“http://www.w3.org/XML/1998/namespace”></stream:stream> Gtalk Acknowledge With […]

PHP

PHP Extensions – How and Why?

Posted on

In this short post we will quickly see: How to write PHP extensions? Why to write PHP extensions? However before you could understand what we are going to disucss, I will recommend you to read one of  my previous post How does PHP echo’s a “Hello World”? – Behind the scene . In this post I discussed in brief the backend architecture of PHP. Assuming you have read the previous post, lets discuss on how to build our first PHP extension: Every PHP extension is built out of minimum of 2 files. Configuration file (config.m4) which tells us what files […]

PHP

How does PHP echo’s a “Hello World”? – Behind the scene

Posted on

Have you ever wondered how PHP echo’s a “Hello World” for you on the browser? Even I didn’t until I read about the PHP internals and extensions. I thought may be a few out there will be interested in exploring the other side of PHP, so here we go. In my last post I discussed in brief “How your browser reaches to my server when you type http://abhinavsingh.com in address bar?”. Read through if you have missed out on that. Here I will discuss in brief “How does PHP churns out the content requested on the webpage?” An Overview Here […]

PHP

What happens before you finally viewed this page?

Posted on

Since past 1 week or so I am trying to make a small tiny light weight web server of my own, and for the same I have been referring to dozens of papers, websites, people and what not. I still haven’t finished making one, I am still toggling between Java and Python, since both seems to satisfy my needs and unfortunately I am master in none. While I was digging deep into the theory of how can I make a web server, I cleared many other concepts of mine, which finally leads to this post. “What happens before you finally […]