Just a quickie

Posted on July 29th, 2008

Hi folks, wanted to post a follow-up to my introduction to LAMP servers, in case you found it a little too vague and lacking in detail. (Which was intentional, since I was pitching it towards newbies).

Without advocating any particular distribution / server, be advised that most of the examples I will give here will be based on a debian/UBUNTU system, due to current popularity. You can download and install Ubuntu for yourself, if you have a spare machine, or if not, look out for the ~69MB Ubuntu Server available as a VMware VA (virtual appliance) format.

I also tend to work with RHEL based CentOS distros, from time to time, and of course, the variety of other UNIXes from the collective boxen in the hive. However, they are beyond the scope of this discussion, so assume unless otherwise stated that my examples are running on an Ubuntu server.

Here’s a place to get a useful step-by-step guide on howto get your Ubuntu LAMP server up and running, although it looks as though they’ve been extending it and improving since I last took a copy: http://mysql-apache-php.com/

TIP: cached web pages

Posted on July 23rd, 2008

When developing Web pages, theres nothing so frustrating as making a change and the browser not displaying the result properly. Perhaps the browser has cached the page, and pressing refresh does not work, because it is still displaying the broken copy.

In that case, try CTRL + refresh. If it fixes the problem, you can continue developing. However, bear in mind that your visitors might not be aware that they are seeing cached content. How do you correct that for them?

Try this snippet at the top of every page, in the section:

< meta http-equiv="Pragma" content="no-cache" ><br />
< meta http-equiv="no-cache" ><br />< meta http-equiv="Expires" content="-1" >
< meta http-equiv="Cache-Control" content="no-cache" >

But wait! what if you have 1,000’s of pages? You could do it manually, you could even use a shell script or some PERL wizardry to find all the pages and inject the code into the headers, or you could use a template engine, like Smarty! and insert it just once (in your page header template), and it will appear on every page!!

Update: Aug 2019

Note that the above explanation and solution (now a prehistoric approach) didn’t really make a good distinction about WHEN it should be used – i.e. what ought to be cached and what ought NOT to be.

Static content should be cached. You should also use some form of cache buster mechanism such as an id in the UR, so the browser can detect updated files and know when to fetch them again.

Some pages should not be cached, such as those pages that should vary by user (a logged in user in their /account pages, typically using a session and a cookie) and would typically need to be fresh every time.

If you are using a CDN such as Fastly, or using Varnish, you can give it a pattern so that it can recognise requests for static files. (Remember browsers always send cookies with every request, static or otherwise). Fors URLs which match the static path pattern, you will see that it unsets the $_COOKIE on upstream requests, so the responses can be cached. User content that varies by session (cookie) won’t be cached by Varnish. You could adopt a similar approach with your code, if you do not have a Varnish server

Heres a link that shows you how to set the headers in a few different languages https://stackoverflow.com/a/2068407

Apache, MySQL and PHP (AMP Servers)

Posted on July 22nd, 2008

What is an AMP server? (also known as LAMP, WAMP, XAMPP…)
As the title suggests, Apache, MySQL and PHP (or sometimes PERL) running together make an AMP server. LAMP suggests that they are running on a Linux platform, WAMP denotes a Windows server and XAMPP is a package that can be used to setup an AMP server on Apple’s OS X.

Apache is a web server
MySQL is a database engine
PHP & PERL are scripting languages typically used on web servers.

Whilst PERL (Practical Extraction and Reporting Language) is a very mature and powerful language, novice programmers may find it difficult to start with. PHP on the other hand, was intentionally written with the novice developer in mind, deliberately making it easy for novices to create web pages and applications. It has also matured, and supports Object Oriented Programming concepts, such as classes, Inheritance and so on, has a clean looking syntax resembling C/C++ (simmilar comments, and bracing styles).

It does upset some OO purists as in keeping with PHP’s ‘lets keep things simple for the webbie’ approach meant it has done things in a way that might not be considered ‘true’. For example, it is not a strongly typed language, and it recently changed its default behaviour for passing by value and passing by reference.

If none of that made any sense to you, don’t worry!! You could start out with PHP writing things in a procedural style, and find that as your skills develop, you will discover that PHP can grow with you, and you can begin to adopt the OOP style.
(Object Oriented Programming, vs Procedural style.)

Now this post is deliberately short, and meant as an introduction to new users. There are other alternative databases, webservers, and scripting languages, and I am not suggesting they cannot be used instead. In fact, the concepts which apply to an AMP server could equally apply to IIS, PoorMan, Lighthttpd, PostgreSQL, Oracle, SQL server, and so on – feel free to experiment and find what works best for you! =)

 

System Architecture

Posted on July 22nd, 2008

It is not rational to build a system with no idea of what it should do:

Define the problem (analysis phase)
Investigate the issue
Isolate root causes
Create a solution (synthesis phase)
Implement

Tempus Fugit

Posted on July 16th, 2008

Okay, so times move on, and looking back I see the merits of a gaming console. Especially the uniquely physical next-gen Wii and its Wii-mote controller. (I was getting tired of Nintendo-thumb and mouse-cramp in my shoulder from the PeeCee.) Sure the graphics aren’t the hottest, but I grew up to respect plot, gameplay and overall ‘playability’ than fancy graphics or music.

Sure enough though, times change, and I became aware early on that hardware was going to constantly evolve, graphics would improve and things would keep getting better.

I saved myself a LOT of money by not buying stuff from new. Heck, I just love the shiny new smell of a circuit board just pulled from a mylar anti-static bag, but you can get some pretty good stuff thats only 2-4 years old for a fraction of the price.

The only problem with being an incurable hardware addict, was kicking the eBay habit. I’d found a supply of UNIX gear, and now I was hooked. I poured thousands away…

My First Post

Posted on July 14th, 2008

“Hello, World!”

Welcome to my Blog.

—–BEGIN GEEK CODE BLOCK—–
Version: 3.1
GAT d? s: a30 C+ UL+++$ UI++ P– L++ E— W+++ N+ o– K+ w+ O M+ V- PS PE Y+ PGP- t+ 5- X+ R tv– b+++ DI++ D++ G e+ h—-(h++) r++ z+
——END GEEK CODE BLOCK——

(Stuck? Try http://www.geekcode.com/geek.html for explanations)