PHP, ASP and Whitebeam

Site Map
 
Home
 
Application Guide
  Quick Start
  PHP and ASP
  Writing Apps
  Applications
  Tutorials
  Samples
Reference
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

PHP, ASP and Whitebeam

This page provides some comparison between PHP, ASP and Whitebeam in order to introduce Whitebeam to people familiar with those technologies. If you haven't used these technologies then you may be better placed reading the full tutorial on writing Whitebeam applications.

The subjects covered are:

  • The layout of pages - comparing Whitebeam against PHP and ASP
  • Markup - How Whitebeam uses XML to move beyond scripting
  • Libraries - Interfaces to backend technologies
  • Scaleability - What happens when your application outgrows your current server - or the currently available fastest serer?
  • ...and finally a Summary

Page structure

ASP, PHP and Whitebeam all store programs in text files, and each of those files contain special markers that highlight where to insert dynamically generated content. In the Whitebeam environment these files generally have the extension '.rhtm' or '.whtm' but of course you can use any extension. The following shows two similar pages - one for PHP and one for Whitebeam

PHPWhitebeam
<html>
 <head><title>Hello World</title></Head>
 <body>
   <?php
      // Server-side PHP
      $msg = "Hello World";
      echo();
   ?>
   <?= "The message is'$msg'" ?>
 </body>
</html>
<html>
  <head><title>Hello World</title></Head>
  <body>
    <?rbscript
      // Server-side JavaScript
      var msg = "Hello World";
    ?>
    <?= "The message is '"+msg+"'" ?>
  </body>
</html>

The major difference between the structure of Whitebeam pages and those of the other two technologies is that Whitebeam files must be valid XML markup. Whitebeam is an XML Application, while the other two are more simply text substitution processors. XML is an inherent feature of Whitebeam. Although PHP uses XML 'friendly' syntax - the files are not XML. This is illustrated by the perfectly valid PHP file:

  <html>
       <head><title>Hello World</title></Head>
       <body>
         <?php $aValue = 22 ?>
         <table border="<?php echo($aValue)?>">
            ...

As far as PHP or ASP are concerned - a program file has no structure - it is a text file on which simple text substitution is performed.

  • Whitebeam is an XML engine that invokes a script engine as necessary. A Whitebeam file is an XML file and can be manipulated as such and used with existing XML editing tools.
  • ASP, PHP are text based technologies - they have no intrinsic awareness of XML or document structure

This difference may seem rather subtle - and if all you do with Whitebeam is to write PHP like applications but using JavaScript then the differences will probably not be apparent. However by making Whitebeam an XML application - and having the programs structured using valid XML unleashes a whole set of additional facilities such as:

  • Use XML and HTML editors to see document structure
    Many PHP and ASP applications hide all their output in streams of print statements. The only way you can see the output structure is by running the application and looking at the output. A Whitebeam page allows you to represent the application structure in XML, which can be modified using commercial XML/HTML editors such as dreamweaver.
  • Attach JavaScript behaviour to XML tags
    Whitebeam allows you to create your own new tags and attach JavaScript behaviour to them. For example - create a tag for a menu item. Whenever the engine encounters that tag when it executes the page it runs the associated JavaScript - the outoput from the script replaces the tag in the output document sent to the client.

    You can also use this behaviour to 'transform' existing tags. I could for example redfine <h1> tag to automatically insert a link at the start of a page whenever it is encounrtered, providing an automatic table of contents.
  • DOM manipulation of the source
    Because a Whitebeam page is an XML document at the lowest level - Whitebeam provides a DOM like access to that document structure at run time. You can included a number of XML sub-structures within your doucment - then select the appropriate on for output, maybe based on browser or current section number or type of person logged into the site.

Beyond Scripts

ASP and PHP provide mechanisms that can substitute 'output' in place of 'script'. In the ASP and PHP the only way of achieving this is through script, which can make the pages being generated look very clumsy, which in turn makes maintainance and development more difficult and costly.

In a Whitebeam application, JavaScript is primarily a technology for adding procedural functionality to pages. Page structure on the other hand is best described in an XML markup language, which Whitebeam provides as a set of XML markup that is embedded in application pages.

To illustrate how this improves the structure of a page consider the following simple example of repeating a block of output for rows in a table:

PHPWhitebeam
 <html>
   <head><title>Hello World</title></Head>
   <body>
     <table>
       <?php
          for ($i=0;$i<count($rows);$i++)
       ?>
       <tr>
         <td>Row <?= $i ?></td>
         <td><?= $rows[$i] ?></td>
       </tr>
       <?php>
          endfor;
       ?>
      </table>
   </body>
 </html>
<html>
  <head><title>Hello World</title></Head>
  <body>
    <table>
      <rb:repeatfor expr="var i=0;i<rows.length;i++)">
        <tr>
          <td>Row <?= i ?></td>
          <td><?= rows[i] ?></td>
        </tr>
      </rb:repeatfor>
    </table>
  </body>
</html>

Or an even simpler example - conditionally including a block of text if a user is logged into the system

PHPWhitebeam
 <html>
   <head><title>Hello World</title></Head>
   <body>
     <?php
        if ($isLoggedIn)
     ?>
       <p>Welcome back to our application!</p>
     <?php>
        endif;
     ?>
   </body>
 </html>
<html>
  <head><title>Hello World</title></Head>
  <body>
    <p rb:test="isLoggedIn">
      Welcome back to our application 
    </p>
  </body>
</html>

This latter example also illustrates the power of a system that understands the XML hierarchy. An entire block of XML can be conditionally included simply by making the parent tag conditional (rb:test) on the result of a JavaScript expression.

Whitebeam provides a rich set of XML markup to allow you to define your pae structure rather than having to use PHP control constructs.


Libraries

We've covered the basic syntax of Whitebeam and how JavaScript and XML markup combne to provide a powerful development framework. We've shown the syntactical similarities between Whitebeam, ASP and PHP. The XML structure of a Whitebeam page makes it very easy to build XML based applications. By itself this functionality has little practical use. It could for example be used as a more understandable translation language than XSLT, for those familiar with standard procedural languages, but that's about it!

To write an application requires access to a number of underlying functional technologies. Obvious among these are the ability to store persistent data between page access, recognise client sessions and associated data, implement a robust security model etc. Each development environment provides these in a different way, but in each as an underlying application programming interface (API).

The PHP approach

PHP provides a very rich API built as a set of function calls to underlying modular interfaces. As PHP has developed and grown a larger following so more effort has been placed into adding interfaces to just about any kind of function you could need for a web application. This is perhaps one of the strengths, and weaknesses of the PHP environment. The libraries cover a lot of functionality, but has been implemented by a wide variety of organisations and individuals. The result is a feature rich environment, but one that can be daunting to new users of the environment.

The APIs provided to PHP developers also tend to be very thin, in that they map almost directly down to an underlying applications interface. The result is very little consistency and very little abstraction, leading to a different API to talk to, for example, Postgres, mySql and DB2, despite the fact that they are all SQL databases. To see the breadth of coverage visit the PHP documentation library

The philosophy followed by the PHP libraries tends to mean that you have to know a lot about the underlying technology before you can use an API.

PHP effectively provides a procedural interface allowing direct access to underlying software, but to use that technology you must learn both PHP - and how to use that technology. To write a database driven application using PostgreSQL for example you to learn PHP, HTML andSQL.

Whitebeam Libraries

Whitebeam provides an intuitive, well documented object orientated set of APIs that abstract away the underlying complexity in order to reduce barriers to entry for new users. While developers can get down to the underlying functionality, it is perfectly possible to build a feature rich database driven application without ever having to learn SQL. Even where the user wishes to get to the underlying functionality the Whitebeam aim is to provide a consistent interface to similar techologies. You really shouldn't have to change your code substantially to move from one database technology to another!

Whitebeam library functionality falls into two main categories:

  1. Session/request related functions
    For example sending text to the browser, reading data from a form, accessing session information associated with this request.
  2. Other associated objects
    Covering making HTTP requests, sending emails, making database connections etc. These are generally objects that are transient and last for a single browser page request only.

The first of these is represented as an object called 'rb'. This object contains a set of objects representing different aspects of the current operating environment, for example sessions, catalogues, sessions and the page generation itself. You'll find a list of all the Whitebeam classes here.

The second, transient objects, are represented by a number of classes within the system. So an HTTP request is represented by an instance of the 'HttpRequest' class.


Scaleability

PHP has evolved over time from a fairly basic origins - the system developed from the scripting language. Most of the functionality available to developers is in the form of added libraries. Most of these have been developed to for the most common 'single-server' web application environment. Scaleability has never been a major issue addressed by the developers of PHP. There is no doubt that you can develop reliable, scaleable applications, but in that case you have to write your own framework to make it happen.

The core libraries provided with PHP lend themselves to single server applications. The standard session management functions store session information in a file on the local file-system. If you have a vedry successful site and your server can't cope, your general solution is to get a bigger server. If you have the biggest server you can afford then your only options are to replace the core functionality with your own session tracking code, using for example a database to store session information.

Whitebeam luckily inherited a very mature, industry standard scripting environment (ECMAScript/JavaScript thanks to the guys at Mozilla). Our interest was not in providing the language but rather in how to harness that language to develop scaleable applications. All of the standard libraries in Whitebeam have been developed with scaleability in mind. Using standard libraries, if you have performance issues, you can make use of industry stanard load balancers to run your application on two servers concurrently. None of your code has to change because the Whitebeam architecture separates session data into a separate service accessible by all servers.


Summary

Whitebeam has a number of similarities with PHP and ASP. Page layout can look very similar and you can do very similar things with each of these technologies.

Whitebeam very much builds on these architectures using internationally standardised building blocks of XML and ECMAscript. Where PHP and ASP process a text page for embedded script, Whitebeam introduces a two-parse approach, processing an properly formatted XML file and then executing behaviours associated with specific XML markup within those pages. Whitebeams knowledge of the structure of the page as a hierachy of tags allows some very sophisticated manipulations to be achieved very easily.

Alongside the core page structure, Whitebeam provides a rich set of data storage and manipulation allowing sophisticated database driven applications to be written with no knowledge of the underlying technologies. Whitebeam abstracts away the need to learn SQL or other technologies. At the same time it provides those interfaces if required for specialist applications.

Finally Whitebeam addresses in a transparent manner the issue of scaleability and reliability, allowing a developer to take an application initially running on a single server and to run that same application unchanged on multiple servers using standard load-balancing products.


The quickstart guide will give you more details about Whitebeam

Whitebeam release 1.3.36
(loadtime : 8ms)