Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Building up from a small PHP setup to an enterprise one

I've often described Well House Consultants as a "mom and pop" company - a small outfit where we provide a niche service (IT Training and a business hotel in Melksham). We make heavy use of PHP on our web sites, and it serves us very well, being quick and easy for us to code and running well on our servers. But is it scalable? What if we wanted to move on from our "mom and pop" system to a system that's good across a whole big international organisation?

Here's the archirecture of a straight forward system, using simplest design and coding principles:

The (orange) server box receives requests from the web site visitor's computer (the browser), and reads the PHP files of fthe disc as required. PHP is what I describe as an "HTML++ language" - in other words, the code is embedded within the HTML in the form of extra tags ... the server then takes those extra tags, runs the code that's in them, and sends the result of running that code back to the browsers, in the course of which data associated with the code that's running may be saved to / read back from the disc.


You may think that model would work fine for our little company, but actually we've moved on. Let me show you how.

For starters, the original model mixes up the look and feel of the web site with the business logic. In other words, the HTML directives on formatting the output and the calculations to extract data from its source were all combined into a single lump, meaning that both Lisa (on graphic art) and myself (on coding) had to get involved with the same files, and also meaning that a look and feel that could be shared across numerous pages had - in the simplest of models - to be duplicated. And that gave rise to maintainance issues, and an awful lot of work if things were to be changed. The first stage of improving this, by separating out common elements into shared files, is not illustrated by diagram here - the second diagram goes on to show the second stage of separaration.

By splitting the web site / page elements into three or four distinct sections, each with a clean and clearly defined interface to the others, different elements can be maintained by people with different skill bases, and different applications can more easily share common templates, and ./ or different data sets and their access. Sometimes you'll hear this described in PHP terms as the "4 layer model", where you have the top level controlling the general flow of URLs to code, the business logic which looks after the data, the web helpers which provide data to web transposition, and the template which provides the standard look and feel into which results are "mailmerged". And that's refined further into being desribed as "MVC" - Model, view, controller - see [here].

The second illustration in this section (the one just above) shows our server split out into Model, View and Controller - together with "Router" which hasn't made it into the acronymn, but fulfills the vital role of converting the incoming request (the URL and its data) into a decision as to which piece of program to run, and what and how to pass the data in. In other words, the router will make decisions like converting a URL such as
  http://www.wellho.net/share/devizes.html
into a request to run the script called wikipage.php with an extra parameter string
  pagename=devizes&editmode=0

But there's a great commonality of approach in what I've described above in just about every web application. Most applications require sticky fields - data cells where the data is validated when submitted, and echoed back into the same field when it's found to be invalid. Most applications require a continuity of data from one page to another - sessions. Most applications require the taking of data from the model to allow admin user edits, and then saving back, modified, into the data store. And rather than the programmer have to write these for each and every application, the common current approach is to use a Framework. The most commonly used Framework in the PHP world in Zend ... the concept is also present if you use other languages on your web site - you many have head of / used Django if you're programming in Python or Rails if you're Ruby based.


Your data isn't typically going to reside totally within and be directly handled by your model code. Whilst you could write data file handlers within your PHP or have them included within the Framework, it's more logical to use an already-written and well tested system which itself includes all sort of things like record locking, easy data changes, data intergrity validation and a good access system to make programmatic access esay. And the dominant such system for quite a while was / has been SQL - a relational database system where the data is stored in tables, tables are joined to each other to avoid the need to repeatedly hold common data, and the internal format is such that simple edits can be done efficiently without big file rewrites. "SQL" - the Structured Query Language - has a number of flavours and implementations; you're most likely in the Open Source world to come across MySQL, but you may also come across PostGRESql, Oracle, Microsoft's SQL Server and others. All of these SQL engines run as a separate service that's typically accessed by the model element of your PHP MVC code, and the frameworks often include standard logic to help you map database records into PHP objects and vice versa.

As an aside (not on the diagram), you may also come across SQLite - which is a lightweight SQL database with a different structure. SQLite does not run as a separate server - it's a library that's built into your PHP (or other language) and you directly pass it SQL directives which it has implemented to run on local files, giving you many of the benefits of SQL over plain text files, but without a separate server which (frankly) can be overkill for many applications.


Looking wider than SQL, there are other ways that the model can access underlying data behind the model which may sometimes be more appropriate. A key-value store or a NoSQL database (such as MongoDb) may work better than an SQL system for some applications / users, and for more complex requirements a whole further service layer may be the better solution. You're looking at SOAP, at XML, at RESTful technology here, where a library within the model contacts a further server - usually via an http or https connection. So in effect your server becomes a browser to a second level server. Very often, these second level servers are running Java applications to look after the data ...

Many of the major web applications these days - Twitter, Facebook, Google Maps, and Flickr to name but a handful provide their own "API" - Application Programmer Interface. In essence, these APIs are server based interfaces, using http and/or https, to make requests and get results from back end servers so that the web applications can be used through your own applications as well as directly through your browser. Usually, authorisations / keys are required, and you're advised to cache results that are retrieved.


This is all very well in concept, but how does one design, experiment with, and test these more complex web based systems. We've moved a very long way indeed from a web site that's providing a static page of information into a full application in many cases, and we can't just go working on and chaning the live server in the middle of the night. So - in this diagram, we've added a second server. This is being used for testing and development - trying things out, making sure that no code works, with access (read only, one hopes!) to common back end servers.

Not shown in this diagram - you may have development and test servers, and with those servers you'll also have resource reporistories such as SVN (SubVersioN) to allow your developers to be able to check out and check in code changes, secure in the knowledge that their colleagues aren't amending it in parallel. Such a system also allows rollback to see the code at various release levels, so that your developers have an easy route to troubleshoot older versions if they're working on code that's common across a whole range of sites.


But where are your developers? London, Manchester or Glasgow? Or San Diego, Bangalore or Amsterdam? And will they have quick and easy access to your test and development servers, or will those servers be "firewalled" at your networking centre in London / Chicago / Fremont and hard for your developers to access?

Modern laptops are very powerful - absurdly powerful - and an excellent option these days is to run your server software - at least the first level - on your own machone. You can then research and develop locally in the USA, the Netherlands, India or up a Welsh mountain without the need for a fast VPN connection back to HQ.

Virtual Machines (using software such as Virtual Box from Oracle, or VMWare) allow you to reproduce the front end server's environment on your local machine - be it a PC or a Mac - and give you your own testing environment. And application configurations can be used to control whether you're going to access backend services from within your own organisation, Twitter and elsewhere ... or whwthe you'll run those on your local machine too.

This virtual machine approach is sometimes referred to as a "sandbox"; you have a separate part of your own computer runningan independent copy of the environment that's on your main company's server, yet with no need to be linked in to it while you're testing, and with no need to worry about the effect on other users while you develop, experiment, try things out, do timing trials and all of the rest. The main server carries on serving your company's customers, irrespective of infinite loops and gross coding errors that you might occasionally make, and you're no longer in an environment in which you need to time your work to happen at the times of day that resources are available.


In the final diagram, I show the system as it might be set up for a larger organisation. But here's an interesting question - "what do WE do at our expanded mom and pop outfit", where last week we had 22,000 different visitors to our two main web sites, between them accessing 62,000 pages. Other statistics include total log file size of around 350 Mbytes for the week, and over 1 million different individual requests of the server - these are the sorts of stats that salesmen will quote and they're impressive not not very useful!

It turns out that - even at our small size - it's worth our while to be using the same practical architecture. I have a sandbox copy of Virtual Box, running Centos Linux, Apache, PHP, Zend Framework and MySQL on my MacBook Air (yes, really) and I can even develop and test in the train as I travel - including in Standard class with the horrid seat pitch. And for our other site, which uses a much simpler model, we're running Apache httpd with PHP, and MySQL, directly on our own MacBook Pros.

Back end services? Yes - we use those ourselves too. You'll find me picking up services from Twitter, Google, Stop Forum Spam, Journey Check, The Highways Agency, and the BBC. For some I'm using their own APIs, for others MagpieRSS, and others are using the PHP file_get_contents directly.

These subjects are covered (to some extent) in our Deploying LAMP and PHP techniques courses. However, they are very much "crossover" topics that may not fit neatly into any one course - please email me with your specific requirements so that I can give you best training advise.
(written 2012-12-16, updated 2013-01-05)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H307 - PHP - Web2 and caching
  [1633] Changing a screen saver from a web page (PHP, Perl, OSX) - (2008-05-06)
  [1647] Exchange Rates - PHP with your prices in your users currency - (2008-05-19)
  [1733] memcached - overview, installation, example of use in PHP - (2008-08-02)
  [1812] Starting Ajax - easy example of browser calling up server data - (2008-09-27)
  [1813] Ajax - going Asyncronous and what it means - (2008-09-28)
  [1814] Javascript/HTML example, dynamic server monitor - (2008-09-28)
  [1926] Flash (client) to PHP (server) - example - (2008-12-06)
  [1995] Automated server heartbeat and health check - (2009-01-16)
  [2196] New Example - cacheing results in PHP for faster loading - (2009-05-24)
  [2321] Uploading and Downloading files - changing names (Perl and PHP) - (2009-08-04)
  [2545] Scraping content for your own page via PHP - (2009-12-21)
  [3029] PHP data sources - other web servers, large data flows, and the client (browser) - (2010-11-04)
  [3094] Setting your user_agent in PHP - telling back servers who you are - (2010-12-18)
  [3186] How to add a customised twitter feed to your site - (2011-02-27)
  [3458] On this day ... one PHP script with three uses - (2011-09-26)
  [3999] Handling failures / absences of your backend server nicely - (2013-02-08)
  [4055] Using web services to access you data - JSON and RESTful services - (2013-03-29)
  [4075] Further recent PHP examples - (2013-04-28)
  [4106] Web server efficiency - saving repetition through caches - (2013-05-30)
  [4136] How do I post automatically from a PHP script to my Twitter account? - (2013-07-10)
  [4627] Caching results in an object for efficiency - avoiding re-calculation - (2016-01-20)

H114 - Sourcing, installing and configuring PHP
  [192] Current MySQL and PHP paths and upgrades - (2005-01-28)
  [316] Development Environments - (2005-05-19)
  [481] PHP upgrade - traps to watch - (2005-10-31)
  [934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
  [1667] Checking server performance for PHP generated pages - (2008-06-06)
  [1688] cannot restore segment prot after reloc message - PHP / httpd - (2008-06-26)
  [1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
  [1768] What is built in to this httpd and PHP? - (2008-08-23)
  [1936] Quick Summary - PHP installation - (2008-12-12)
  [2317] How to make a Risotto (PHP build style) - (2009-08-02)
  [2433] Controlling, supressing, enabling PHP error messages - (2009-10-02)
  [2589] Your PHP code does not work? Here is where to start looking. - (2010-01-18)
  [2646] Compile but do not run PHP - syntax check only - (2010-02-22)
  [3132] Virtual Hosting with Apache http server - an overall scheme, and avoiding common pitfalls - (2011-01-14)
  [3635] Parse error: parse error, unexpected T_STRING on brand new web site - why? - (2012-03-03)
  [4319] PHP - some quick fixes if scripts have issues, and how to use our support - (2014-11-19)
  [4437] Adding a PHP build option, rotating an image based on camera data, and a new look at thumbnails in PHP - (2015-02-22)

A603 - Web Application Deployment - Further httpd Configuration
  [345] Spotting a denial of service attack - (2005-06-12)
  [466] Separating 'per instance' data from binaries and web sites - (2005-10-16)
  [526] Apache httpd - serving web documents from different directories - (2005-12-12)
  [550] 2006 - Making business a pleasure - (2006-01-01)
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)
  [649] Denial of Service ''attack'' - (2006-03-17)
  [662] An unhelpful error message from Apache httpd - (2006-03-30)
  [755] Using different URLs to navigate around a single script - (2006-06-11)
  [853] To list a directory under httpd on a web server, or not? - (2006-09-02)
  [1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
  [1080] httpd.conf or .htaccess? - (2007-02-14)
  [1121] Sharing the load with Apache httpd and perhaps Tomcat - (2007-03-29)
  [1207] Simple but effective use of mod_rewrite (Apache httpd) - (2007-05-27)
  [1351] Compressing web pages sent out from server. Is it worth it? - (2007-09-14)
  [1355] .php or .html extension? Morally Static Pages - (2007-09-17)
  [1377] Load Balancing with Apache mod_jk (httpd/Tomcat) - (2007-10-02)
  [1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
  [1551] Which modules are loaded in my Apache httpd - (2008-02-23)
  [1554] Online hotel reservations - Melksham, Wiltshire (near Bath) - (2008-02-24)
  [1564] Default file (MiMe types) for Apache httpd and Apache Tomcat - (2008-03-04)
  [1566] Strange behaviour of web directory requests without a trailing slash - (2008-03-06)
  [1619] User and Group settings for Apache httpd web server - (2008-04-22)
  [1636] What to do if the Home Page is missing - (2008-05-08)
  [1707] Configuring Apache httpd - (2008-07-12)
  [1762] WEB-INF (Tomcat) and .htaccess (httpd) - (2008-08-20)
  [1767] mod_proxy and mod_proxy_ajp - httpd - (2008-08-22)
  [1778] Pointing all the web pages in a directory at a database - (2008-08-30)
  [1939] mod_proxy_ajp and mod_proxy_balancer examples - (2008-12-13)
  [1954] mod_rewrite for newcomers - (2008-12-20)
  [1955] How to avoid duplicating web page maintainance - (2008-12-20)
  [1974] Moving a directory on your web site - (2009-01-03)
  [2060] Database connection Pooling, SSL, and command line deployment - httpd and Tomcat - (2009-03-01)
  [2272] Monitoring and loading tools for testing Apache Tomcat - (2009-07-07)
  [2478] How did I do THAT? - (2009-10-26)
  [2900] Redirecting a page - silent, temporary or permanent? - (2010-08-03)
  [3133] An image from a website that occasionally comes out as hyroglyphics - (2011-01-14)
  [3449] Apache Internal Dummy Connection - what is it and what should I do with it? - (2011-09-19)
  [3862] Forwarding a whole domain, except for a few directories - Apache http server - (2012-09-17)
  [4001] Helping search engines with appropriate 400 error codes - (2013-02-11)
  [4307] Identifying and clearing denial of service attacks on your Apache server - (2014-09-27)


Back to
Lesson 1 in programing - write clean, reuseable and maintainable tidy code
Previous and next
or
Horse's mouth home
Forward to
Zend / layout of MVC and other files in an example application (PHP)
Some other Articles
Testing code coverage (have I tested everything?) in PHP
Testing classes for your PHP website with PHPUnit
The week before Christmas
Zend / layout of MVC and other files in an example application (PHP)
Building up from a small PHP setup to an enterprise one
Lesson 1 in programing - write clean, reuseable and maintainable tidy code
Objects in PHP - Revision
PHP revision ... by example.
Christmas Bus Schedule for Melksham - First Bus
10 reasons why I travel the night before a course starts
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3955_Bui ... -one-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb