PHP vs Ruby on Rails, Part 1

Over the last few weeks, I’ve been asked by both friends and clients, “So what is that thing called Rails I keep hearing about (and/or keep hearing you talk about)? How is it different from PHP?” Typically I give them a three-part answer that’ll I’ll now iterate for the blog. While this is far from a complete comparison, hopefully it will be useful to some people out there.
The first thing to keep in mind when trying to form a comparison between PHP and Rails, is that PHP is just a language. It’s a scripting language that has a lot of useful functions that make adding dynamic content to web pages easier than its predecessors. What PHP is not (and what Rails, in fact, is) is a framework. In software terms, frameworks are generally tools and pre-built objects that help you create a solution faster by not reinventing the wheel.

More specifically, Rails is a full-stack framework. Full-stack basically means that when you decide to use Rails it will provide practically all of the tools necessary all by itself. While you are welcome to use other tools for sections of Rails’ functionality, most current Rails developers are not (and for obvious reasons described below.

So PHP is just a language. When you choose to use PHP to build a significant web application what you’ll want to do is look for tools and pre-built objects that are written in PHP. Some are packaged together in frameworks. Other times you’ll assemble them ala cart (a database abstraction layer here, a template system there). Sometimes building systems this way makes a lot of sense, but other times the overhead of divided tools makes for more work than it might be worth.

In Rails, they follow a mantra of “Convention Over Configuration.” With this in mind, Rails will follow industry conventions to make your job easier whenever possible. One example where you can see this in action is with page templates.

In Rails, if you have, for example, a BlogController and it has a method called list, Rails will automatically use the list.rhtml file inside of a folder called blog in your views folder. Not only that, but Rails will automatically pass on any instance variables you were using in the controller so that the view has access to them.

Now, when I am doing something similar in my own PHP apps, I have to manually instantiate the template object, manually pass references to any variables I know the view will be interested in and then manually tell it what template file to use. While all that manual code is pretty simple and easy to write, on even medium-sized apps it starts to take a toll on the leaness of the codebase.

This is one of the many reasons I like Rails. It will follow obvious conventions when possible but allow you to override the convention with a specific command; in this case to use a template file other than list.rhtml if needed.

Conclusion for part 1: PHP is just a language. Rails is a full-stack framework. PHP has lots of useful tools; they just don’t gel as well and usually require more configuration.

Part 2 will be posted soon. In it, we’ll look into the Ruby language and how it differs from PHP. Continue Reading in Part2

Is mobile Linux ready for the enterprise?

Cutting costs by deploying Linux is a well-established strategy on the server and even the desktop, but what effect could it have on the cost of mobile computing?

Very few people lie awake at night fretting over their choice of mobile operating system. In fact, very few people even know what operating system their handset uses.

Yet, despite this probably healthy level of ignorance, a quiet revolution is taking place in the mobile industry. Linux is slowly winding its way onto the smartphone, although no-one is really certain what it will look like when it gets there.

Part of the problem -- although some would no doubt view it as a strength -- is the number of organisations pushing mobile Linux. There are two main industry groupings dedicated to the cause: the Linux Mobile (LiMo) Foundation and the Linux Phone Standards (LiPS) Forum. Some companies are members of both. Others belong to one of the groups, but are implementing their own flavours of mobile Linux. It is little wonder that mobile Linux's chances of making inroads in the enterprise space have been played down by some very vocal critics.

Symbian, which has a certain foothold in the enterprise thanks largely to its work with Nokia, took aim at the open-source operating system in July, when its head of enterprise business market development, Andrew Moran, dubbed mobile Linux "fragmentation city" and claimed it was "completely unfeasible" for business use.

Gartner analyst Nick Jones has a more objective stance but he agrees that the platform is not yet consistent or standardised enough to be a serious proposition. "I would advise IT managers not to have anything to do with mobile Linux at this point in time," says Jones. "Imagine I'm an IT manager contemplating standardising on a mobile platform. I want something rich enough to deliver applications, that's available from multiple manufacturers, offering a decent range of handsets with corporate features. Linux just falls down on all of those."

However, those who have thrown their weight behind the movement are confident that it will succeed in an analogous way to Windows Mobile. Bill Weinberg, general manager of business development at the LiPS Forum, certainly sees Microsoft's mobile play as the best point of comparison for mobile Linux as a development platform, although he suggests that "Linux does it with a single code base end to end, not five or six distinct code bases with their own histories and bugs".

"Microsoft has a dominant space because it is very easy to extend corporate applications onto mobiles using Windows Mobile, but we're seeing Linux increasingly adopted as the operating system for use in corporate environments," says Adam Lawson, product director at Trolltech, the company behind the popular open-source development platforms Qt and Qtopia. "We would expect to see that trend extend into the mobile space in good time."

Lawson added that governments in countries such as Brazil and China have officially backed the use of Linux in the public sector, and touted the security of open source as a reason for this broad adoption. "Linux from the word go has been designed as a multi-user operating system," Lawson said. "It is easier to restrict access to particular data files and capabilities and prevent malicious access by third-party applications -- the raw materials for that are available in Linux."

Lawson also thinks that another key strength of Microsoft's -- Windows' ubiquity and the leagues of developers writing for the platform -- could in turn become a strength of the mobile Linux movement. "Microsoft skills are widely available, but Linux is increasingly taught in universities. There are generations of engineers coming out with the relevant skills," he says.

Trolltech's Qtopia application-development platform, which is built on Qt, is geared towards embedded devices and handsets -- notably Skype's internet telephony devices. "IT managers should be thinking about VoIP," says Lawson. "Expect to see Linux and Qtopia appearing on VoIP phones and desk phones -- you are unlikely to see Windows running on a desk phone any time soon."

Run Internet Explorer on Linux

Most Linux users would be appalled by the idea of attempting to contaminate a Linux installation with any Microsoft product, especially Internet Explorer.However, many Web sites don't render properly using regular Linux browsers, such as Firefox or Konqueror. Other sites either require ActiveX controls or are designed to work only with InternetExplorer. Also, how can you test your new Web design and JavaScriptfor IE if you're an Apache and Linux maven?
For those who may have the need for Internet Explorer without the need to move to another machine or reboot, there is a solution for you: an extremely useful project aptly named IEs4Linux. In this article, we describe how to install and begin using multiple versions of Internet Explorer using Wine and IEs4Linux.
What's IEs4Linux?
IEs4Linux is a small shell script that can be run via a console on any Linux machine with Wine installed. As the title suggests, it allows you to quickly and easily install that most infamous of Microsoft products: Internet Explorer.
The creator of IEs4Linux is Sérgio Luís Lopes Júnior, a 21 year old Brazilian student and self-proclaimed lover of Linux and OpenSource. Naturally, being open source, IEs4Linux is free. However, as with many people working on open source projects, Sérgio's funding comes from the community; if you found IEs4Linux helpful, you can PayPal him a few dollars to continue development of the project.
IEs4Linux relies on the Wine project to supply an implementation of the Microsoft Windows API. The IEs4Linux script actually downloads the required CAB files directly from the Microsoft site; then, using cabextract, copies the files to a new Wine profile. This way, your existing Wine profiles are not affected, and any other software you have running will be just fine. In addition to installing Internet Explorer versions 5, 5.5, and 6, IEs4Linux also can install Flash 9 for you from Adobe.
IEs4Linux is a GPL product; however, Internet Explorer is a copyrighted product of Microsoft. This means that you will need to be in possession of a valid Windows licence version greater than 95, although it will not be asked for during the installation process
Author's note
For the purposes of this article, I'll assume you're running the latest version of Ubuntu as your Linux distribution. IEs4Linux will work with almost every distribution, but the installation routine varies. This article assumes that you already have Ubuntu Desktop installed and operational.
Depending on how you like to install your software, I have included two sets of instructions, first the graphical (GUI) method and lastly the console (CLI) method.
Installing the required packages

To install all the applications required to enable IEs4Linux to run properly, ensure that you have the Universe repositories enabled. Open the Software Sources configuration screen, which can be found under Toolbar | System | Administration | Software Sources.
Next, you need to select all the repositories for the
CD-ROM/DVD option. You won't need this option. The online repositories are kept
up-to-date, as shown in Figure A. Press the Close button when you're
Figure A

Selecting the required repositories to install Wine and cabextract.

Now it's time to begin installation of the required packages. Go to Toolbar | System | Administration | Synaptic Package Manager.Once it opens, search for Wine and cabextract. Once you find them, press Apply, as shown in Figure B.

Figure B

Installing Wine and cabextract.
Kickin' it old school with the console
You can also obtain the files from the console prompt. To
begin, open a console. You can do this by going to the toolbar and going to
Application | Accessories | Terminal. In the terminal, run the command: apt-get
update && apt-get install cabextract wine.
The install process will begin after pressing [Enter]. The apt-get process download installs all
the files and packages for wine for you.
Getting down to business
Now that you have Wine installed with cabextract,
it's time to download the IEs4Linux files. You can either go to the IEs4Linux Web site,or return to a console to enter this command to download the latest IEs4Linux build:

Figure C shows what this looks like.
Figure C

Downloading the IEs4Linux Installer.

After you have downloaded the latest build tarball, you need
to cd to the directory where you downloaded tarball to if you did not do so from the console. This can be done easily with the command cd ies4linux-*. Next, enter the command tar xzvf ies4linux-latest.tar.gz in the console to decompress the tarball and change directories into the build directory. Finally, to launch the IEs4Linux script that will begin the installation process, type ./ies4linux.

You will be lead through a text-based series of screens that
will ask you questions about what versions of Internet Explorer you want to
install, as shown in Figure D. The first question asked will be if you wish to install version 5 and 5.5 of Internet Explorer; you can make that decision for yourself. In addition to installing Internet Explorer, IEs4Linux will also install the Flash Player plug-in automatically.
Figure D

Running the IEs4Linux Installer.

After a few minutes, the script will download all of the
required files and install them on your computer automatically. Additionally,
links on your desktop will be created to Internet Explorer making for quick
access. The Internet Explorer launch binaries will exist in the newly created
directory bin in your home directory.
For quick access on command line, run ~/bin/ie6 to launch Internet
Explorer version 6. You'll see IE run, as shown in Figure E.

Figure E

You should now have Internet Explorer running in Linux.

Congratulations; you have successfully installed Internet
Explorer version 5, 5.5, and 6 on your PC. With the assistance of IEs4Linux, it
is possible to have Internet Explorer accessible to you as a tool on any Linux
system that can run Wine.
Variations in other distributions
The install process for other distributions will be
different according to that distro's package system. But the rest is the same after that. For example, in Gentoo, the series of commands would be:
emerge --sync && emerge wine cabextract.
For Fedora, the commands to install wine and cabextract are:
yum -y install wine*

yum -y install cabextract

For Mandriva, the directions are:
urpmi wine cabextract
For more distributions and instructions, please visit the IEs4Linux site.
Known issues
There are a number of known issues with the Internet Explorer version installed by IEs4Linux. Some of these include:

  • VML does not work.

  • PNG transparency does not work even when using hacks (a consequence of the
    "CSS filter" bug).

  • Windows Update does not work.

  • JavaScript error dialog does not open.

  • Modified toolbars are not saved.

  • ActiveX may not work with some special cases.

The install of Internet Explorer made by IEs4Linux doesn't
have the JavaScript debugging enabled by default, which can be quite
frustrating when you know there is a bug on the page, but can't get the error message.To get around this, you will need to enable JavaScript debugging.

In the menu bar, go to Tools | Internet Options to open the
Internet Options dialog. Next, press on the Advanced
tab and scroll down to the Browsing section. Uncheck the list item Disable Script

Torvalds releases Linux kernel 2.6.25

Linus Torvalds has released the latest version of the "stable" Linux kernel, version 2.6.25, which includes changes to Wi-Fi support, virtualisation, real-time scheduling and file systems.

The kernel, which was released approximately 10 weeks after its predecessor, includes broader Wi-Fi hardware support and the integration of more Wi-Fi drivers, according to Linux developers. Among the drivers integrated is Ath5k, which is compatible with chips by semiconductor system Wi-Fi developer Atheros.

On the virtualisation front, the KVM x86 emulator has been updated with more instructions and components, designed to improve performance and compatibility. Virtual prototyping platforms framework Virtio has also been updated, while paravirt_ops now works on the x86-64 architecture.

Read This:

Linus Torvalds at Linux.conf.au 2008

Linus Torvalds was the star guest at Australia's annual Linux conference. ZDNet.com.au once again took a video crew to Melbourne in January and caught up with the man behind Linux.
Read More »

Performance improvements were made to the Completely Fair Scheduler (CFS) real-time technology, which gets its first support for LatencyTop, a tool for helping track down latency problems.

The Ext4 file system also saw changes, and now uses checksums to ensure journal integrity. Ext4 is a journalling file system -- a file system type becoming popular because of its resistance to corruption in the event of a system crash or power failure.

The kernel includes the Smack (Simplified Mandatory Access Control Kernel) security framework, which is based on a set of mandatory access control rules and is designed for simplicity.

Developer improvements to Linux have been showing up as significant reliability gains in the enterprise over the past two years according to a recent Yankee Group survey, which found Linux distributions from Red Hat and Novell have increased reliability by an average of 75 percent since 2006.

However, Linux 2.6.25 implements a policy that could cause problems for some administrators: forbidding proprietary USB drivers access to certain core functionality. Developers warned two years ago this change was coming, but many USB drivers nevertheless remain proprietary. The 2.6.25 kernel includes changes that could cause problems for proprietary USB drivers that take the form of kernel modules.

Such drivers can no longer be compiled with unmodified Linux 2.6.25, due to the fact that the licence of an important API is only compatible with drivers that carry a GPLv2 or compatible licence.

Developers included this feature for a time in the development of kernel 2.6.16 in 2006, but it was removed before the kernel was finalised in order to give driver makers an opportunity to produce open-source drivers. However, many drivers remain proprietary.

PHP6 overview

I haven't had much time to follow the discussion around PHP 6 the last few months. Finally I took a half an hour to read up on what will happen with PHP come version 6. It was interesting reading and most of the things I really look forward to.

PHP 6, it seems, will make the leap and become a more clean environment - which is something I really appreciate.

The register_globals, magic_quotes and safe_mode will finally disappear and hopefully slowly fade away into distant memory. It seems PHP 6 will even refuse to start if these settings are found in php.ini. Dropping support for the long versions of super globals, like HTTP_POST_VARS, is also scheduled. This is long overdue.

One thing I at first was a bit hesitant to is moving all the database extensions out of the core into PECL. It looks like this is not set in stone and seems to be an ongoing discussion. After thinking about it myself I think it would be the right thing to do. It would boost the usage of PDO and make it more used and thus more mature. It would also clear up some of the confusion among newcomers in the PHP sphere. "Use PDO or make an active choice" - would probably be the best for the future of PHP.

SOAP is widely used today and good support for SOAP has been around as an extension you have to actively turn on if you needed it. It also has many limitations as has been discussed recently on the PECL-DEV mailing list. There is also a new PHP SOAP extension being developed that is using Apache Axis 2 from the Apache Foundation. I think what is suggested for PHP 6, to fix most of the remaining issues as well as implement support for some of the security extensions of SOAP, is the right way to go. I really think SOAP needs to be natively supported in PHP rather than having to depend on an external library as is the case with the Axis2 extension.

Named parameters to functions and methods has also been discussed. Even though I can remember how I enjoyed writing Smalltalk code with named parameters more than 10 years ago in university I don't think it should be implemented in PHP. Luckily those that decide on the roadmap thought the same as me.

Something that really annoys me today is that you can call methods both statically and dynamically whether they are marked static or not. It just doesn't make sense. This will in the yet distant PHP 6 generate an E_FATAL. Now that makes sense.

This above is all well but it is in the planned additions it gets really interesting. PHP 6 will have the opcode cache APC included in the core distribution. It will not be turned on by default - but I think this is the first small step towards a future with JIT compilation or something along those lines. Good UTF support is another thing that is sorely needed and it seems a lot of work will be directed to clean up the string handling in PHP 6.

With PHP 5 we got lots of object orientation and functionality around XML as well as the database abstraction PDO. It seems that PHP 6 will be more of a cleanup than anything else. I like that even though I am not sure the major version number should be bumped up. I read somewhere, I can't remember where, that PHP 6 will be around in the end of the 2006. December is just 9 months away...

PHP : Using CURL to validate URL address

About CURL

cURL stands for client URLs (and is also written as just curl or Curl),is a commandline tool for working with URLs.. Withg cURL you can access Web sites,FTP files, and do much,much more.PHP can use cURL via the shell_exec() and other system functions. But PHP also supports libcurl, a cURL library.

Below code will validate whether given URL(http://www.suresh-mobileweb.blogspot.com) is valid using cURL.


$ch = curl_init(); //initialize curl session
curl_setopt ($ch, CURLOPT_URL, "http://www.suresh-mobileweb.blogspot.com"); //connect to URL
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); //return response as srting
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0); //unlimited time connection
curl_exec($ch); //execute the session
$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE); //get URL http response

if($httpcode != 200){ // the URL is not valid - print the result
echo "invalid Site URL";
}else{ //valid
echo "valid Site URL";

curl_close($ch); //close the curl session

PHP : Performing IP Geolocation

One of the questions that i commonly see in suppport foums or in PHP newsgroups is how to identify what country a user resides in. Although the server where PHP is located could be anywhere in the world and the user could be located anywhere in the world,it is possible to make a geographic match.

Every computer must have an IP address to have Internet access(or to connect to any network). An Internet service provider(ISP) assign a computer an IP address from a pool of valid address only they have access to. By knowing a computer's IP address, which PHP puts in $_SERVER['REMOTE_ADDR'], one can know the ISP and thereform, the country. Hence the name IP geolocation. New GeoIP databases can even predict the city and state although with less accuracy.

To Learn more about IP Geolocation, download source code and databases , online demos , please visit http://www.maxmind.com site.


One resource I found suggested that IP geolocation is very accurate on the country level, probably close to 95 percent. On the city and State level, that accuracy may dip down to 50-80 percent, depending upon the database being used.Use commercial database instead of Free/Open Source to get more accurate results.

Mobile Barcode(m-Ticketing)

And why not use the mobile phone itself as a ticket for the cinema, for a show or for travel? This is the brainchild of the France Telecom research team. Based on the idea that we take our mobiles with us wherever we go, they conceived the idea of displaying a ticket on the screen, in the form of a barcode. After a transaction over the mobile or the web, it could be downloaded via a WAP site, or sent to the customer's terminal as an image SMS or an MMS (depending on the characteristics of the subscriber's mobile phone).

The "ticket" dematerialised in this way could resemble a simple conventional barcode, like that you see on most products on sale, or be in two dimensions and then contain far more data. For example, for a travel coupon, the barcode could contain complete information about the transaction (customer's name, number of persons travelling on the ticket, means of payment used, time of departure, time of arrival, and so on). The virtual ticket is thus stand-alone and these data no longer have to be retrieved from a data bank located on-line or remotely. The customer simply presents his mobile screen in front of a reader similar to those used by supermarket check-outs to validate his ticket.

By doing away with paper, this innovation makes life easier for the user, who can now place his order right up to the last moment (unlike remote sales of paper tickets which have to be booked in advance). It also avoids ticket queues. This service, called m-Ticketing, could complement those built around m-Payment: after booking, then paying, m-Ticketing is a solution for rapid authorisation to access a service. For the operator, apart from the mobile phone being a way of making life easier, this enables a relationship of trust to be established with the customer. Furthermore, depending on the partnerships set up between the operator and the organisation proposing the service, a percentage remuneration mode could be set up on a case by case basis.

The applications of m-Ticketing are vast: from shows to sporting events, through transport services, and so on. A first experiment was already conducted in April 2004 in Mo�tiers with the road transport company Transdev. Any Orange customer going to a ski resort in the Tarentaise area or the Belleville valley was able to reserve his coach ticket from Mo�tiers station and receive it on his mobile phone in the form of a 2D barcode.

Another major area of potential applications is "couponing". People frequently forget their reduction vouchers or loyalty cards at home when going shopping. The idea is therefore to use the mobile, our everyday companion, as a medium for receiving virtual reduction vouchers or loyalty points, in the form of conventional (rather than 2D) barcodes. The discount will therefore become effective simply by presenting the mobile phone screen at the check-out.

70% of current mobile phones in France would be potentially compatible with this type of service, but this proportion is gradually rising as the terminal population is renewed. The next step in this groundbreaking project in Europe will be to combine partners (large cinema chains, etc) and equipment suppliers (readers, portals, etc.) to achieve a critical mass of potential users. In the longer term, the aim will be to look at ways to diversify into increasingly sophisticated applications, such as access control using biometric data, and so on.

Mobile Coupons

Its an electronic ticket delivered by mobile phone that can be exchanged for a financial discount or rebate when purchasing a product or service.Coupons are issued by manufacturers of consumer packed goods or by retailers, to be used in retail stores as part of sales promotions.

Distribution Channels:
1) SMS: In only 160 characters the merchant need to explain offers and conditions
2) MMS: Use of Multimedia Messaging to deliver the coupon. MMS allows to enhances the campaigns but there is higher cost associated with this message
3) WAP Site: Consumer can access the WAP site in their mobile and download the coupon
4) Application: With a downloadable application the merchant can send a coupon
5) Image: The merchant distributes an image with the offer
6) Email: The merchant distributes the printable coupon, URL or code for use on the internet.
7) Physical: A coupon can be delivered to the consumer via conventional postal carrier

1) Drive traffic to stores/events/entertainment attractions/services
2) Add values to the purchase
3) Direct discount to the consumer
4) Targetting possibilities

5) Leverage the Distributions.