Posts

Showing posts from 2011

Drupal Bootstrap Database

This is the 3rd article in the series covering DRUPAL v6 bootstrap process. As the bootstrap name implies, this phase covers initializing a connection to a database. The phase begins by including 'database.inc' , which is a database abstraction layer allowing developers to use different database servers with the same code base. One of the functions defined by this library is the db_set_active() function, which is invoked by the bootstrap database phase. This function is used to activate a database used by queries in later phases or during page building and rendering. The function begins by checking if the global variable $db_url is empty. Recall that in the phase #1 - DRUPAL_BOOTSTRAP_CONFIGURATION, this variable is set to the value specified in settings.php unless it is still set to the default string of ' mysql://username:password@localhost/databasename' . In that case, $db_url is simply set to empty string ''. This would indicate a first time insta

get XML Namespace Elements using PHP SimpleXML

PHP has a great SimpleXML library that converts XML to an object that can be processed with normal property selectors and array iterators. I’ve been using this quite a bit lately to process some XML documents. The library documentation isn’t that great when it comes to processing Namespace Elements within your XML document. An example of such use case is when you are parsing an RSS feed that has XML Namespace elements . Consider the following example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?xml version = "1.0" encoding = "UTF-8" ?> <rss version = "2.0" xmlns:opensearch = "http://a9.com/-/spec/opensearch/1.1/" xmlns:dc = "http://purl.org/dc/elements/1.1/" > <channel > .... <item > <title > My Title </title > <description > My Item </description > <dc:publisher > ABC </dc:publisher > <dc:creator > DEF </dc:creator > <dc:date &g

Drupal bootstrap early page cache

The previous article in this series focused on phase 1 of the Drupal bootstrap process (DRUPAL_BOOTSTRAP_CONFIGURATION). This article will now focus on the second phase - DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE. The early page cache phase is one that might not accomplish much for some Drupal sites, but for some others can play an important role in improving a site's overall performance by minimizing latency when delivering content to a user's browser. This is accomplished by caching already rendered pages for anonymous users (i.e. haven't logged in). This phase is run early in the bootstrap process as it doesn't rely on any later bootstrap phases (used to gather content and render pages) and its purpose is to keep latency to a minimum - in other words the sooner it executes, the faster a user receives the requested content. There are two forms of caching with Drupal: non-database and database. The early page cache relies on non-database mechanisms, such as file syst

Drupal 6 Bootstrap Process

Image
When investigating a recent rash of spam user registration on my site I began looking through Drupal core to gain a better understanding of its inner workings and how modules could be used to guard against these nuisances. Like every journey there is a beginning, and for me it all started with index.php. This is not a very big file, but it plays a vital role because access to content on any Drupal site (via HTTP GET or POST commands) is all directed to this one file. It starts off simply enough by including a bootstrap PHP file (bootstrap.inc). This file in turn defines several constants referenced throughout the Drupal code base as well as several core utility functions. Then magic begins The drupal-bootstrap function is called with the constant DRUPAL_BOOTSTRAP_FULL as argument (the function and constant previously defined by the afore-mentioend include file). This function serves to execute a series of phases in order to process all requests coming to the server. How many p

login script with php mysql jquery

Image
Introduction Today we are making a cool & simple login / registration system. It will give you the ability to easily create a member-only area on your site and provide an easy registration process. It is going to be PHP driven and store all the registrations into a MySQL database. Step 1 – MySQL First we have to create the table that will hold all the registrations. This code is available in table.sql . table.sql 01 -- 02 -- Table structure for table `tz_members` 03 -- 04   05 CREATE TABLE `tz_members` ( 06    `id` int (11) NOT NULL auto_increment, 07    `usr` varchar (32) collate utf8_unicode_ci NOT NULL default '' , 08    `pass` varchar (32) collate utf8_unicode_ci NOT NULL default '' , 09    `email` varchar (255) collate utf8_unicode_ci NOT NULL default '' , 10    `regIP` varchar (15) collate utf8_unicode_ci NOT NULL default '' , 11    `dt` datetime NOT NULL default '0000-00-00 00:00:00' , 12    PRIMARY KEY