Thursday, June 18, 2009

Ways of utilizing PHP by a web server

There are three ways a web server can utilize PHP to generate web pages:
  • CGI wrapper
  • Module in a multiprocess web server
  • Plug-in for a multi-threaded web server
CGI wrapper:

The first method is to use PHP as a CGI wrapper. In this case. an instance of the PHP interpreter is created for every page request. The page is offcourse a PHP page. The instance is destroyed after the request is served.

Module in a multiprocess web server:

A multiprocess server typically has one parent process which coordinates a set of child processes. The child processes actually do the serving up web pages. when a request comes from a client, one of the children, who is not serving any client at that moment, is allocated to serve the request. This means that when the same client makes a second request to the server, it may be served by a different child process than the first time. This method currently includes Apache web server. This is the most popular method.

Plug-in for a multi-threaded web server:

This method uses PHP as a plug-in for a multithreaded web server. Currently PHP 4 has support for ISAPI, WSAPI, and NSAPI (on Windows), which all allow PHP to be used as a plug-in on multithreaded servers like Netscape FastTrack (iPlanet), Microsoft's Internet Information Server (IIS), and O'Reilly's WebSite Pro. The behavior is essentially the same as for the multiprocess model.

Thursday, January 1, 2009

Opening file having extension .z

This type of file is Unix Compressed File. This is an standard file format supported by many programs. This compression format is used to compress or "pack" files on Unix servers to save disk space; incorporates a simple compression algorithm that has been mostly replaced by GNUzip compression (which creates (.GZ files)).

File can be decompressed on a Unix machine by typing uncompress filename, where "filename" is the name of the file you want to decompress.

There is a lot of programs listed below for uncompressing/openning this type of file:

Sunday, July 27, 2008

apache didn't start after installing subversion

I installed apache long before. Recently I installed subversion and thought everything is OK. But actually it wasn't. When I tried to start apache, i got this error:

$ /usr/local/apache2/bin/apachectl start
[Mon Jul 28 11:13:10 2008] [warn] module ferite_module is already loaded, skipping
[Mon Jul 28 11:13:11 2008] [warn] module php5_module is already loaded, skipping
Syntax error on line 1048 of /usr/local/apache2/conf/httpd.conf:
Cannot load /usr/local/apache2/modules/mod_dav_svn.so into server: /usr/local/apache2/modules/mod_dav_svn.so: undefined symbol: dav_xml_get_cdata

This time, it took little time to solve this problem. I reinstalled apache using these steps:

$ ./configure --prefix=/usr/local/apache2 --enable-dav --enable-so
$ make
$ sudo make install

And everything is ok now :)

Monday, July 21, 2008

Using svn and got "Unrecognized URL scheme."

This morning, I built subversion-1.5.0 from source using the ./configure, make and make install. Then I tried to check out a repository and got this error:
$ svn checkout http://svn.assembla.com/svn/blog1/ --username azim.babu
svn: Unrecognized URL scheme for 'http://svn.assembla.com/svn/blog1'

It seemed to be a curious problem to analyze. So I did some googling and found these from http://subversion.tigris.org/faq.html :

Subversion uses a plugin system to allow access to repositories. Currently there are three of these plugins: ra_local allows access to a local repository, ra_dav which allows access to a repository via WebDAV, and ra_svn allows local or remote access via the svnserve server. When you attempt to perform an operation in Subversion, the program tries to dynamically load a plugin based on the URL scheme. A `file://' URL will try to load ra_local, and an `http://' URL will try to load ra_dav.

The error you are seeing means that the dynamic linker/loader can't find the plugins to load. This normally happens when you build Subversion with shared libraries, then attempt to run it without first running 'make install'. Another possible cause is that you ran make install, but the libraries were installed in a location that the dynamic linker/loader doesn't recognize. Under Linux, you can allow the linker/loader to find the libraries by adding the library directory to /etc/ld.so.conf and running ldconfig. If you don't wish to do this, or you don't have root access, you can also specify the library directory in the LD_LIBRARY_PATH environment variable.

So what I got is that I was not able to setup the SVN on my ubuntu box properly. Here even after compiling the source I was not able to enable the support of ra_dav module for http and https protocol. So I did a little googling again and found that I was missing neon. So I download neon from http://www.webdav.org/neon/neon-0.28.1.tar.gz , extract the tarball and install neon using ./configure, make and make install.
Then I recompile subversion as follows:
$ ./configure --with-ssl --with-apr=/usr/local/apache2/bin/apr-config --with-apr-util=/usr/local/apache2/bin/apu-config --with-neon=/usr/local
$ make
$ sudo make install

A little explanation of the above options are:

--with-apr : prefix for installed APR, path to APR build tree, or the full path to apr-config

--with-apr-util : prefix for installed APU, path to APU build tree, or the full path to apu-config

--with-neon : Determine neon library configuration based on 'PREFIX/bin/neon-config'. Default is to search for in a subdirectory of the top source directory.

As I installaed neon without any option during configure, it should be /usr/local for my case :P

Although all these steps may seem to be very much intuitive for many, I think for newbies, this type of blog post may provide some sort of quick help. :)

Monday, March 31, 2008

libdbi..TEXT Datatype..MySQL VS PostgreSQL

I am currently working with porting a very much sophisticated & advanced NLP software/system written in C++ which is actually targeted to run using a MySQL Database.

My current or short term target is to port it to PostgreSQL.

After created necessary & equivalent tables in PostgreSQL database, I wrote a script to transfer data from MySQL database to PostgreSQL database.
After some fixing it worked fine.

Then I ran the software using PostgreSQL database. Alas...data loading failed :(

I found that if I just changed the database driver from "pgsql" to "mysql" it worked fine.
The problem occurred if database driver is changed from "mysql" to "pgsql"

I thoroughly investigated the table definitions and data in various tables and found that the problem was not originated from the database end.

So, why I faced the problem?? Why???? :(

After loosing some valuable hairs:(, I found this:

In case of MySQL database, libdbi-driver for MySQL wants to fetch TEXT as binary and thats why in the original source code of the software, dbi_result_get_binary was used to fetch TEXT type data.

But, in case of PostgreSQL database, this is different. i.e. libdbi-driver for PostgreSQL wants to fetch TEXT as string not binary.
So, the fix is to replace dbi_result_get_binary with dbi_result_get_string

Ahh...The world is beautiful again :D


Saturday, March 29, 2008

Adding custom DISTINCT ON behavior

In a typical query we sometimes use Distinct keyword to eliminate duplicate rows.

SELECT DISTINCT column1, column2, column3.... FROM table1 WHERE ....

This elimination of duplicate rows occurs after the result table has been generated & the selected columns has been processed (if needed)

Two rows are considered distinct if they differ in at least one column value.
Null values are considered equal in this case.

But this default & obvious consideration can be customized. How? Ok..let me explain with an example.

Say we have a table named Student

Name Bengali English Math
Alex 70 85 96
Barnabus 96 70 85
Alfred 96 70 84

Say, you want to consider those students as distinct who has different total marks of Bengali, English & Math.
So the first two students are not distinct, the first & third are distinct and the 2nd & third are distinct.

SELECT DISTINCT ON (Bengali+English+Math) Name
FROM Student;

Now think yourself about a case where you can apply this custom behavior of Distinct and if you find any then don't hesitate to let me know ;P

SQL..Problems with Distinct ON

The DISTINCT ON clause is not part of the SQL standard &
its result is not always determinate.
So although it is often the most obvious alternative & convenient also, think twice before using it.
Ask yourself:
1. Do I want sql written by me to be portable to sometoher DBMS?
2. Do I want to avoid indeterminate nature of result?

If any of the above question is NO, then try to use GROUP BY and subqueries in FROM to implement the same thing and avoid Distinct ON.