Monday, March 31, 2008

PROXY for PEAR channel


I recently submitted a bug report on PEAR regarding a long standing issue with the PEAR installer tool: there is no support for HTTP 302 (redirect). This condition effectively limits the hosting possibilities of PEAR channels e.g. a PEAR channel can not be accessible through a DNS cname aliases.

Problem

Suppose I have hosted a PEAR REST channel on Google Project @ http://mediawiki.googlecode.com/svn and now I would like to make this channel friendly through a nicer URL like " mediawiki.pear.jldupont.com ".
(note that the above is just an example: the channel on which I used the method described below in not yet publicly available)

Solution

The solution involves setting up a PROXY. This time around I have managed the feat with Apache using proxy_module 'mod_proxy.so' : in my vhost configuration, I have added:

<VirtualHost mediawiki.pear.jldupont.com:80>

ServerName mediawiki.pear.jldupont.com

DocumentRoot /var/www/vhosts/mediawiki.pear.jldupont.com

#PERFORMANCE tuning
#NOTE: not strictly required for the PROXY functionality
SetOutputFilter DEFLATE

ProxyRequests Off
ProxyPass / http://mediawiki.googlecode.com/svn/
ProxyPassReverse / http://mediawiki.googlecode.com/svn/

</VirtualHost>

Friday, March 28, 2008

1000's of Free Icons

I have amassed a reasonable collection of free icons. The collection is stored on Flickr and available here.

Wednesday, March 26, 2008

Zend PHP opcode disassembler

I have found a disassembler for Zend's PHP Opcode: Xcache (PHP opcode cacher) contains a PHP script which provides opcode disassembly services.

APC 3.0.17 and PHP 5.2.4

It would appear that APC 3.0.17 breaks down with PHP 5.2.4, that's at least my conclusion from upgrading my website's MediaWiki v1.11.0 installation.

Tuesday, March 25, 2008

PEAR Web Installer

Here is a quick tutorial on how to install PEAR's WEB Frontend installer.

1) Shell command: pear install PEAR_Frontend_WEB
2) Create file pear.php in the desired web directory with the following content:

I suggest putting this file in a separate folder with proper web server access permissions (i.e. htaccess, htpasswd etc.)
3) Adjust directory permissions for the PEAR system folders download and temp (on my LINUX system, these are located in /tmp/pear)
4) Adjust directory permissions for the PEAR classes folder (on my LINUX system, these are located in /usr/share/pear)

Thursday, March 13, 2008

PEAR channels updated automatically

A marvelous new tool is available to the general public since yesterday: SproutBuilder. I decided to give it a try:






Above is a sprout automatically updated of all the PHP PEAR channels I know. The list is composed of entries I add to my Del.icio.us links with the tag pear-channel. Then this list is processed through a YAHOO! Pipe and finally embedded in the ''sprout''.

Wednesday, March 12, 2008

FeedBurner Awareness Data as RSS feed

I grew tired of logging on my FeedBurner account page to get my statistics data so I devised a Yahoo! Pipe to automate things. The Pipe can be used on any publicly accessible FeedBurner feed: here.

Monday, March 10, 2008

1and1 Linux VPS

It would appear that 1AND1 Linux VPS come now with Fedora Core 6 - 64bits. I really don't mind except when:
- PEAR isn't installed
- PECL neither (of course) ... and does not work even after fixing PEAR

Some good news though: yum is installed by default. Hooray!

Installing PEAR
Step 1: cd /tmp
Step 2: wget http://pear.php.net/go-pear
Step 3: php go-pear
Step 4: When prompted for the installation prefix, use /usr/share
Step 5: Try-out the pear command: pear

Installing PECL extensions
Getting PECL extensions to compile is a little bit more tricky...
Step 1: yum install gcc
Step 2: yum install php-devel

Even with this effort, I wasn't able to use the pecl command and had to resort to go through the pear command instead. See example next.

Installing PECL / APC
Step 1: pear install pecl/apc
Step 2: cp /usr/lib/php/modules/apc.so /usr/lib64/modules/php/apc.so
Step 3: vi /etc/php.d/apc.ini
Step 4: following step 3, edit apc.ini with extension=apc.so




Sunday, March 9, 2008

Optimistic and Pessimistic Creation

Say one needs to create objects in one namespace in a controlled fashion (i.e. avoid duplicates, avoid loss); what strategy can one employ?

The Problem

The basic issue one has to deal with comes from the fact that possibly multiple processes are actively accessing a given namespace thereby collisions can occur: in namespace N, process 1 creates object O1 whilst process 2 does the same (i.e. creates object O1).


The left-hand side diagram illustrates the problem: the competing processes race to win the creation event during which time a meta-stable state exists i.e. no one process can be certain (to a reasonable degree) which will win the race.




Two main strategies
There are (at least) two main strategies to address the problem: an optimistic and a pessimistic one.


The optimistic strategy can be used in patterns where a process is considered reasonably alone in accessing a given namespace. Example: a user accessing is private file folder.

The pessimistic strategy must be employed in situations where multiple processes potentially access a given namespace. Example: an application's user creation flow.

Optimistic Strategy
The optimistic strategy consists in a simple procedure. The system:

  1. verifies if object[X] exists
  2. creates object[X] if it does not exist
The notation object[X] just means: an object with for identifier X.

Pessimistic Strategy
The pessimistic strategy is outfitted with a probabilistic equivocation reduction process. The system:
  1. verifies if object X exists in the namespace
  2. generate a reasonable unique identifier UID
  3. creates a new identifier [X;UID]
  4. verifies if an object with for identifier [X;UID] exists in the namespace
  5. following #4, if no object exists, wait for Y units of time
  6. verifies if any object with identifier prefix X exists
  7. if the process' object with [X:UID] comes as first created (assuming multiple hits), then the process wins the creation race
An Application: Amazon S3 WEB Service

Say an application must be crafted with a system for registering users. Obviously, this process must be controlled: the system must be designed to deal with conditions such as:
Use Case: user X tries to register to the application with user-name UN1 at the same time as user Y goes for UN1.

One way to deal with the creation of unique user records on Amazon S3 I propose is:
  1. Generate a long unique identifier (e.g. 32bytes)
  2. Prepare a string identifier I/UID where I is the wanted identifier
  3. PUT-OBJECT with for URI /I/UID
  4. Wait for Y seconds (e.g. 3seconds)
  5. LIST-OBJECTS with for prefix /I
  6. If the object with for prefix /I/UID comes out to be the first created, then the process wins
The advantage of this algorithm stems from the fact that only 2 HTTP requests are necessary for each creation instance.

Thursday, March 6, 2008

Enabling APC for PHP CLI scripts

Include the following lines in the php.ini script corresponding to the one used by PHP for running CLI scripts:

apc.enabled = On

apc.enable_cli = 1


Don't forget that the initialization file for the CLI operation of PHP is most probably different than the one used with Apache.

Using Google Alerts as Forum Notification method

One irritant on the WEB I found a solution for: have you ever posted questions or comments to a site that didn't include automatic email notification when the question/comment got feedback? It happens to me all the time.

Google Alerts to the rescue!

I now use GoogleAlerts to track my whereabouts on the WEB. The usage pattern is simple: just form the habit of always signing your post with a distinctive mark and set an alert on this mark. With my name, this is easy as it is not so common.


Greasemonky Quick Search

I have to sift through countless RSS feeds all day seeking more information based on keywords I find. I wanted to automate the process just a bit so I devised a GreaseMonkey Firefox user script.

Usage is simple: just select the text to search and press " alt c " which will automatically bring-up the result page on Google Search.

One can find the script here on UserScripts.org.

Tuesday, March 4, 2008

Embedding FreeMind mindmaps

FreeMind is a very handy (and free ;-) tool. I recently started playing around Google Mashup Editor and wanted to document in my way the API; I thus used FreeMind yet again.

I have embedded the mindmap in a Google Page available here.

Embedding the mindmap is easy:


and place the Javascript code at the bottom of the page: