The Discordant Opposition Journal Issue 10 - File 5
Cold Fusion - A Primer
24 December 2000 by "Timeless"
Introduction
When web servers first became popular on the 'Net, it was mostly just to serve up static web pages. Gradually people saw the potential of making web sites "dynamic", having the ability to give a more interactive and personal experience to the surfer. This spawned the need for web servers to be able to integrate their functionality with custom-made programs. So the Common Gateway Interface (CGI) was created which would allow programmers to create web-based applications. Special web pages could be requested which would actually run a program instead of just handing out a web page to the user. The program would create HTML code on the fly and send it back to the web server software, which in turn gets returned to the user's browser software over the 'Net.
However, with new solutions there are new problems. When a CGI program is called, a whole new instance of that program (and sometimes it's interpreter too) needs to start up in the computer's memory. It would initialize itself each and every time, it would re-connect to databases each and every time, and also tidy up afterwards... yes, you guessed it... each and every time. This simply put way too much load on the web servers, especially on busy web sites. Load balancing was very crude and expensive in those days too, so an alternative had to be invented.
It was decided that the web application software could start up at the same time as the web server software, and only be shut down when the web server was stopped. To allow for this kind of functionality, various web server APIs (Application Programming Interfaces) were created, namely: ISAPI (for IIS web server), NSAPI (for Netscape's web server) and WSAPI (for Web Site Pro's web server). At the same time Apache web server was just starting to get popular, and it used a similar mechanism but the integration was done through "modules".
Now, web application programmers could create fast and efficient software that need only initialize once and could serve many concurrent web users without having to have an enormously powerful computer to handle the resources. Remember that new solutions bring new problems? It turned out that writing server API code was very complex. Programmers needed to be very aware of multithreading and simultaneous processes and all the potential problems arising out of their use. So some programmers started building standard server API software that could be scripted later without having to worry about how it all works inside the "black box". This way, programmers could concentrate on writing the business logic of the web application itself. This idea gave birth to a whole new bread of software called Application Servers. Microsoft created Active Server Pages (.asp script files), Allaire created Cold Fusion Application Server (.cfm script files) and Sun (I think) came up with Java Server Pages (.jsp script files). Later on, PHP was born and used a language very similar to Perl for it's scripting language.
Each application server technology was very similar to the next in the way the code was run. The surfer would use their web browser software to request a page off a web server over the 'Net. The web server software would check to see if it was a dynamic page that needed processing by the application server software. If so, the page would get processed and all server-side scripting code would get removed from the resulting web page before returning it to the web server software. The web server would then send the page back to the surfer.
Introducing Cold Fusion Application Server
Cold Fusion Application Server is currently built to run on Windows 98/NT, Solaris, Red Hat Linux and HP/UX. It makes use of core server API provided by the leading web server software developers (Apache, Microsoft, Netscape, O'Reilly). It is often dubbed "the glue" when it comes to bringing together various internet-enabled services. It is completely extensible, which means that if it can't do it already a programmer can probably get it to do it with a bit of his own code. It comes out of the box with the ability to "talk" HTTP, HTTPS, POP3, SMTP, ODBC, natively to some other databases such as Oracle, LDAP, XML, Radius Authentication and FTP to name just some of the more important ones. It has the ability to integrate into the operating system itself allowing use of the file system, program execution, system registry, etc. All protected by an advanced security system that suits both single project web servers and multi-client web application hosting. It is completely scalable and is very well suited to Enterprise-level web applications (check out www.afternic.com for example - .cfm is everywhere - and those boys get some serious hits!). Cold Fusion Application Server even has the built-in ability to do software-based load balancing, and hardware-based load balancing is also possible too (speaking from experience).
Enough About The Intro, Let's Look at Code
To demonstrate how easy this language really is to use I'd have to show you some example code. Based on your current CGI experience (if any), you can then judge how efficient and cost-effective it is to develop web applications using Cold Fusion. Here's an example, that if saved in a single web page (index.cfm) will count how many times each surfer has viewed that page. Note that any <cf...> tags will get interpreted by Cold Fusion and are stripped out before the page gets returned to the surfer...
----->8---(Snip! Snip! Copy text after this line into index.cfm)--------
<html>
<head><title>Cold Fusion Example</title></head>
<body>
<cfset newCounter = 1>
<cfif isDefined("cookie.counter") is true>
<cfif isNumeric(cookie.counter) is true>
<cfset newCounter = cookie.counter + 1)
<cfelse>
<!--- goodness! people will actually
hand-modify contents of cookies
just to see what happens! --->
<cfset newCounter = 1>
</cfif>
</cfif>
You have visited this page
<cfoutput>#newCounter#</cfoutput> times!
<cfcookie name="counter" value="#newCounter# expires="NEVER">
</body>
</html>
----->8---(Snip! End of text)-------------------------------------------
You might want to try this for yourself. You'll need to download and install a web server on a computer, then download and install a demo version of Cold Fusion Application Server from http://www.allaire.com/. Once everything has been set up you can request your web page using a web browser and you should get back the following HTML code when you view the page for the first time:
<html>
<head><title>Cold Fusion Example</title></head>
<body>
You have visited this page
1 times!
</body>
</html>
Note that all the <cf...> tags are removed, and the #newCounter# variable's contents was inserted (the number 1 in this case). Note also the extra white space left behind in the resulting document. This white space can also be removed using some other <cf...> tags that are built into Cold Fusion.
Now try to remember all the code you need to write to make simple queries to your SQL databases using the other programming languages you're used to. Well, by complete contrast, here's how Cold Fusion would do it (it's insanely easy):
<cfquery name="listPeople" datasource="mydatabase">
SELECT * FROM PEOPLE
</cfquery>
<cfoutput query="listPeople">
#listPeople.firstname# #listPeople.lastname#<br>
</cfoutput>
Of course there are many more attributes you could have used and you can achieve any kind of complexity you like. You can even call stored procedures in the database, or pass BLOBs and CLOBs (just ask the next Oracle guru about that and he should be impressed).
Free Stuff?
Okay, so Cold Fusion Application Server is not free, but hey it's certainly worth a lot more than they charge for it. However, if you still want to use it and want it at the "right price" (free), then you can always make use of Cold Fusion Express. Cold Fusion Express is a feature-limited version of Cold Fusion Application Server. It will get you started without the need for the cash outlay. Be sure to check out the feature comparison matrix too (search Allaire.com), because you may find that Cold Fusion Express is all you need.
I Can Make Some Money?
Oh yes! :) Cold Fusion programmers can often dictate their own employment packages because it's a skill that's currently in great demand.
Associated Tools
You can also get Cold Fusion Studio. Simply put, it's an awesome development environment for creating Cold Fusion, HTML, JavaScript web applications.
References, links, etc.
Allaire - http://www.allaire.com/
Get Cold Fusion from there, and also check out the custom tags you can download from the developers area.
Experts-Exchange - http://www.experts-exchange.com/
Get independent help from other developers there, not just Cold Fusion either.
Disclaimer and Legal Stuff
Blah, blah, lots of registered trademarks mentioned in here, check with Allaire, Microsoft, Netscape, O'Reilly, Sun, Apache, etc. The views expressed in this article are not necessarily the views of the companies mentioned in this article. The author cannot be held responsible for any incorrect statements in this article because it was late at night when he wrote it. The author maintains copyright over all the material in this article and it may not be reused or distributed in part or in full without express written consent from the author. The article is based on the author's own personal experiences and perceptions.
Advertisement
,,+++:,
_+++::,,,,,::+++_
:+:,- -,:+:
:+,, --,,,,,,,-- ,,++
:+,_ ,:+++- -+++:, _,+
+:, -,+: :+:- _++
-++:,,,,,,,,,:+++ +++, _,+,,,:++-
,+,,- -,++ ++,- +:, :+ -,,+:
,+,- _,,,,,,,_ -,++ ++,- -++- _:+_- -,+,
-:, -,++:+, _,+_++:,- _,+++,_ -,:++_+, ,+,++,- ,:_
_+_ ,+- :+- ,: +,, ,+:_- ,,+ : _+: -:, _+
++- ++ ++- ,+ :++,_ -,++ +- -++ ++- -+
,+- ,+ ++- ,+ ,+:_ _,++__:+, +- -++ +: -+
+,_ ,+: _+_ _:, _++, _:++_ ,:+, ,: _+_ ::, _,+
+:_ _,:+,_ _++,_- _,++ ++,_ _,::+++++::,_ _++
::, _+, :+ _,++ ++,_ --_-- ,::
,+:,- ++_ -,+,,,++_ -++,,- -,:+,
++++:++- ,:+_ -+++++::::+++++
_+, ,,+, ,+,, ,+_
+:, ,,:+++++++++:,, ,++
,+:_- --- -_:+,
++:,_- -_,:++
_+++++++++++_
Timeless logo Copyright © 2000 - Timeless
(ASCII art by Timeless using ASCII Picverter)
http://www.timeless.co.zw/
home of:
- CD AutoRun - make trendy multimedia splash screens for your CDs
- CD DocRun - directly launch programs, documents and URLs when the CD is inserted
- CD Photo Browser - includes automatic indexing of new files on the CD