Section 1.1. Why PHP and Smarty on Large-Scale Web Development?

PHP and Smarty on Large-Scale Web Development > Why PHP and Smarty on Large-Scale Web Development?

Chapter 1. PHP and Smarty on Large-Scale Web Development

To achieve efficiency on your large-scale web projects, start by observing a set of principles. These principles are not meant to stop you from doing what you do best; the goal is for them to help you manage the way software is developed.

The following list describes the principles of large-scale web development:

Modular architecture

A system composed of several components that can be interchangeable and fit together.[*] On a modular architecture it's easier to divide the whole project into specific tasks.

[*] Many frameworks were created to do exactly that. See, for example, the PHP Extension and Application Repository PEAR ( or the Zend Framework (, both written entirely in PHP.

Multidisciplinary teams

Teams where every member has a specific task assigned. Some teams can also be divided into specialized groups like developers, web designers, and software testers.

Version control solutions to maintain builds

Version control[dagger] helps you manage what team members are doing and when you should release a new version (or a build) of your software solution.

[dagger] There are many popular version control solutions, both closed and open source. CVS (, is one of the oldest and most used solutions. Subversion ( is rapidly gaining popularity among open source developers. Visual SourceSafe ( is a solution from Microsoft.

Not building from scratch

Always try to reutilize previously developed components into new solutions. This saves precious time on every new project.

By following these simple rules, you gain control over your projects and everyone on your team therefore becomes much more productive.

Whether you're an engineering manager or a developer, the following sections have great value for you. Next, we show you how PHP and Smarty fit into the large enterprise development schedule.

1.1. Why PHP and Smarty on Large-Scale Web Development?

Instead of asking this question, we ask you "Why not"? Why shouldn't you use this language as your choice for enterprise tasks? How do you make this decision?

According to different authors,[double dagger] there are several criteria that you can use to make that choice:

[double dagger] For a good opinion on how to choose the right programming language, see Spinellis, D., "Choosing a programming language," Software, IEEE, Volume 23, Issue 4, Jul.-Aug. 2006, pp. 62 63.


The language syntax must be easy to learn and to understand. There should be a programming style that developers agree upon. The same logic should be expressed in only one way.


The same program must be able to run on different platforms. There should be a sufficient enough layer of abstraction between the programming language and the host operating system.


The language must provide ways of checking its own syntax and variable types either on compilation or at runtime. It should be easy to debug and test written programs.


There should be available literature (books, magazines, web sites, source-code repositories) about the programming language. It must be easy to get help, hire a consultant, or discuss technical details on the Internet.


Written programs should be easy to maintain or adapt.

To fully understand why PHP is a good choice for large-scale web development, let's see how it fits into the previous list of criteria. PHP syntax is very easy to learn and to understand, as opposed to other scripting languages.

PHP syntax has roots in the C programming language but is increasingly moving into a more object-oriented way of doing things, approaching in some ways the syntax of JavaScript.

Code written in PHP can run on almost every flavor of UNIX, AS/400, MAC OS X, Microsoft Windows, Novell Netware, OS/2, RISC OS, SGI IRIX and Solaris.

It can run as a CGI[ ], and also as a module for popular web servers. PHP is open source software, so even if there isn't a version available for your server or platform, you can still compile it.

[ ] CGI Common Gateway Interface is a protocol for exchanging information between an application and a web server. Although Apache modules made CGI obsolete, it is now gaining ground through the use of FastCGI and as a way to run PHP with the lighthttpd web server.

PHP has a number of mechanisms to check code syntax, beginning with its built-in lint[||] checker. Also, there are numerous debugging and profiling tools, either commercial or free of charge.

[||] Although the PHP interpreter performs a syntax check on every code run, you can do it explicitly on the command line through the -l option of the PHP CLI (Command-Line Interface) or through the less-known runkit ( PECL extension.

PHP is considered the most popular web development language, used on more than 19 million web sites around the globe.[#] It has a community-maintained web site (, where you can find documentation for every PHP function available.

[#] See PHP Usage Stats for December 2006 (

There are numerous code library projects, with PHP Extension and Application Repository (PEAR)[**] being the most popular and most commonly used right now. Another recent framework project is the Zend Framework, a complete MVC[daggerdagger] code library developed by Zend and the open source community.

[**] PEAR PHP Extension and Application Repository. PEAR is the first and most popular PHP code library repository (

[daggerdagger] MVC Model View Controller pattern. For a complete description of the pattern, see Fowler, M., "Patterns of Enterprise Application Architecture," Addison-Wesley Professional, November 2002. (

You should also take a look at eZ Components, a development framework from eZ Systems. eZ Components is a general-purpose, enterprise-ready PHP components library.[double daggerdouble dagger]

[double daggerdouble dagger] More information is available at the eZ Components product page (

In short, PHP is a robust, 10-year-old scripting language driven by a large open source community with different companies offering training, certification, support, and consulting services.

Now that you know why you should choose PHP, you might be asking why you would use Smarty. Why should you use a templating engine in the first place?

The most important reason is the ability to separate logic from presentation. By using a template solution, you effectively have distinct ways to write logic code and presentation or layout. You can then distribute tasks throughout your team more easily.

PHP itself can be used as a template language, but you can gain control over the behavior of the pages if you use a specific interpreted template language. By providing only a "safe" set of functionalities, web designers won't be able to incur any security mistakes or make your web site behave in unexpected ways.

Smarty is an extensible template language interpreted by PHP on runtime. It is available as open source and has a large community behind it. There is plenty of documentation available on the Web and in print.

There are, of course, many other template engines available for PHP. What, then, is the biggest advantage of Smarty? Most of the other engines don't have as many features as Smarty does.

The only comparable template engine is Savant,[ ] mainly because of its speed and features. Its only disadvantage is its lack of a template language.

[ ] Savant is a powerful but lightweight object-oriented template system for PHP. Unlike other template systems, Savant by default does not compile your templates into PHP; instead, it uses PHP itself as its template language so you don't need to learn a new markup system (

Savant templates are written in pure PHP, making it impossible to protect the template code from the full power of PHP. This can be a problem if you need to have control over what your templates can run.[||||]

[||||] For a more detailed comparison, see Maia, et al., "Smarty PHP Template Programming and Applications," Packt Publishing, April 2006.

To conclude, PHP and Smarty are excellent choices for large-scale web development projects involving large teams and tight deadlines. You should feel comfortable using them together.[##]

[##] Some authors argue exactly the opposite, but we think the problem is in their approach to web development, not in the choice of PHP. See, for example, Crane, A., "Experiences of Using PHP in Large Websites" (



PHP and Smarty on Large-Scale Web Development
PHP and Smarty on Large-Scale Web Development
ISBN: 047008023X
Year: 2007
Pages: 20
BUY ON AMAZON © 2008-2017.
If you may any questions please contact us: