| By Joshua Drake | Article Rating: |
|
| November 28, 2001 12:00 AM EST | Reads: |
1,021 |
(LinuxWorld) -- This is a technical overview of the features and use of the LXP Application Server, which was developed by Command Prompt, Inc. Before we begin, let me share a brief disclaimer: I work for Command Prompt. I don't think LXP is a cure-all or replacement for Perl, Python, or PHP, but find it invaluable when used in the right situation.
LXP (also known as mod_lxp) is an application server that runs as an Apache DSO (Dynamic Shared Object) module. It is designed to allow for the simplified development of data-driven, dynamic Web sites involving support for XML, and SQL (through PostgreSQL).
The use of PostgreSQL with LXP is not required, but it is currently the only database LXP supports. Oracle is to be supported soon. LXP is designed to allow even an entry-level developer to quickly provide a useful and marketable product for a customer or department. LXP does this by using features similar to other application servers, such as:
- Simple markup structure
- Ad-Hoc SQL Statements
- XML Support
- Data Parsing
- Direct Apache Sub-Requests
LXP, like PHP, is embedded into the HTML page you are developing, and is parsed as Apache serves the page to the browsing client. Here is a simple example of a PHP script:
<?
if ($hello == "1") {
print ("Hello World");
} else {
print ("It is not true");
}
?>
The following is LXP markup providing the same functionality of the above example:
<lxp>
<if hello="1">
Hello World!
</if>
<else>
It is not true
</else>
</lxp>
Although the above example does not show the true flexibility of LXP, it does provide a brief introduction into LXP markup, and some basic logic. The above example also provides an insight to why LXP was created. LXP is designed to be simple. It is designed so that anyone who can write basic markup (such as HTML) can provide dynamic data to the Web.
Alternative languages such as PHP are designed for developers. They are powerful and have their uses. Anyone who develops in C, C++, Perl, Java, or many other languages could easily become competent with PHP in a Sunday afternoon. LXP, on the other hand, is designed to give more power back to the technical user without limiting developers who choose to use it.
For example, if you wanted to create a connection to a PostgreSQL database and then return the results to a Web browser using PHP, you might code something like this:
<?
$conn = pg_connect("host=localhost port=5432 dbname=somedb user=someuser");
if (!$conn) {
print("Connection Failed.\n");
exit;
}
$result = pg_exec($conn, "SELECT name,c_city
FROM company_auth");
for ($lt = 0; $lt < pg_numrows($result); $lt++) {
$name = pg_result($result, $lt, 0);
$city = pg_result($result, $lt, 1);
print("Name: $name<BR />\n");
print("City: $city<BR />\n");
print("<BR />\n");
}
?>
To provide the same functionality of this script in LXP, the markup could look like this:
<lxp>
<include src="host=localhost port=5432 dbname=somedb user=someuser"
sql="SELECT name, c_city FROM company_auth">
Name: <field name="name" /><BR />
City: <field name="c_city" /><BR />
<BR />
</include>
</lxp>
Now the power of LXP is starting to show through. Notice the simplicity of the LXP markup to generate the same output as the PHP code. Beyond limiting the amount of coding you have to do in LXP to achieve similar results as other languages, LXP also offers some unique features.
Unlike PHP, which will only provide persistent connections using pg_pConnect() (if there is an existing connection to reuse), LXP provides true persistent connectivity to PostgreSQL. For every instance of an Apache child, there is a connection to the PostgreSQL database. These persistent connections allow you to eliminate the startup penalties of starting a new PostgreSQL process to execute queries.
LXP also has a built-in XML parser for such tasks as parsing RSS and RDF content. RDF (Resource Description Format) is the standard XML format for delivering news (and other resources) to the Web. If you have ever visited TheLinuxReview (see resources below), Slashdot, or Meerkat, RDF is the format they use to import and/or export headlines.
If you wanted to use LXP to generate an HTML-based headline listing from an RDF file from Linux Weekly News, you could easily do so with the following snippet of code:
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="2"><TR><TD bgcolor="#000000">
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="0"><TR>
<TD bgcolor="#8888a0" WIDTH="260">
<A HREF="http://www.lwn.net/"><STRONG>Linux Weekly/Daily</STRONG></a>
</TD>
</TR>
<TR>
<TD bgcolor="#000000" WIDTH="260">
<lxp>
<include src="/home/web/ports/headlines/lwn.rss" lastblock="3" method="rss">
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="3" WIDTH="100%">
<TR>
<TD bgcolor="#ffffff" WIDTH="100%">
- <field />
</TD>
</TR>
<TR>
<TD bgcolor="#e0e0e8" WIDTH="100%">
<STRONG>
<field type="url" link="Read More..." target="_blank" />
</STRONG>
<BR />
</TD>
</TR>
</TABLE>
</include>
</lxp>
</TD>
</TR></TABLE>
</TD></TR></TABLE>
This would generate the following output:

Notice that the only actual LXP-specific portion of this markup is the following:
<lxp>
<include src="/home/web/ports/headlines/lwn.rss" lastblock="3" method="rss">
<field />
<field type="url" link="Read More..." target="_blank" />
</include>
</lxp>
Okay, LXP looks interesting, what can't it do?
LXP is designed to be a data/content markup language and not a "programming" language. In other words, in addition to its own capabilities, it is also designed to be a value-add or enabler for other languages. There are some tasks better left to PHP or another language. For example, LXP cannot send e-mail from an HTML-based form. PHP, on the other hand, can. This is where an example of LXP's sub-request functionality can be made. To send e-mail with PHP you could use code similar to the following:
<?
mail("$email","$subject","Hello this is a test email from $email");
?>
You simply cannot do this in LXP natively. However, with sub-requests LXP can provide interaction with the PHP script and allow you to continue within your productive LXP environment. To include a PHP script within an LXP script you would use the following:
<lxp> <include src="mailto.php" method="uri" /> </lxp>
The URI (sub-request) method of LXP supports any known type to Apache, allowing for diverse brokering capabilities. Through the URI LXP method, LXP can pass variable values to PHP. This is powerful because it does not require the writing of obscure code or CGI wrappers to work within both environments.
If we take the above examples and expand on them, we can see how PHP and LXP can work together.
<lxp>
<ifnot sendmail>
<form method="post" action="http://stage.linuxports.com/test.lxp">
Email Address: <input type="text" name="email" /> <BR />
Subject: <input type="text" name="subject" /> <BR />
<input type="submit" name="sendmail" value="Email" />
</form>
</ifnot>
<else>
<include src="mailto.php" type="uri" />
</else>
</lxp>
The source of the mailto.php file looks like this:
<title>My Email Form</title>
<?
mail("$email","$subject", "Hello this is a test email from $email");
print ("You just sent an email to $email");
?>
Over the next month, I will share more advanced articles on the use of LXP with PostgreSQL. Don't worry, though; these articles will not affect my ever-growing-in-popularity SysAdmin column, which millions of people joyously flock to every week to read.
Published November 28, 2001 Reads 1,021
Copyright © 2001 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Joshua Drake
Joshua Drake is the co-founder of Command Prompt, Inc., a PostgreSQL and Linux custom development company. He is also the current author of the Linux Networking HOWTO, Linux PPP HOWTO, and Linux Consultants HOWTO. His most demanding project at this time is a new PostgreSQL book for O'Reilly, 'Practical PostgreSQL'
- Kindle 2 vs Nook
- Is Cloud Computing Like Teenage Sex?
- Confessions of a Ulitzer Addict
- GovIT Expo Highlights Cloud Computing
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Cloud Computing Can Revitalize Your Career as Software Developer
- Ubuntu-based Open Source Linux Mint Tests KDE Version
- Yahoo! SVP Shelton Shugar to Discuss Innovation at Cloud Computing Expo
- Virtualization Journal "Readers' Choice Awards" Voting Is Now Open
- Einstein, Sharks and Clouds: IT Security in the Cloud
- Adobe Flex Developer Earns $100K in New York City
- Amazon Web Services Database in the Cloud
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Is Cloud Computing Like Teenage Sex?
- 1st Annual GovIT Expo: Letter from the Technical Chair
- Ulitzer News: Search vs New Media
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Confessions of a Ulitzer Addict
- GovIT Expo Highlights Cloud Computing
- Twitter, Linked In, Ning and Ulitzer: Easy Personal Branding Strategy
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- The i-Technology Right Stuff
- Linux.SYS-CON.com Exclusive: Linus Discloses *Real* Fathers of Linux
- After Ubuntu, Windows Looks Increasingly Bad, Increasingly Archaic, Increasingly Unfriendly
- Linus' Top Ten SCO Barbs
- A Closer Look at Damn Small Linux
- Netscape Co-Founder's 12 Reasons for Growth of Open Source
- Introducing "Cooperative Linux" - Linux for Windows, No Less
- *POINT - COUNTERPOINT SPECIAL* What's Wrong with the Open Source Community?
- Where Are RIA Technologies Headed in 2008?
- Linux.SYS-CON.com Exclusive: What Would UserLinux Look Like?
- i-Technology Viewpoint: The New Paradigm of IT Buying
- Is Linux Desktop-Ready Yet...or Not?






























