by Marc Plotz
PHP or DIE()
It’s been a few years since I echo’d my first HELLO WORLD script. PHP has developed and evolved and yes, it has changed since it was first devised as little Perl extensions on Rasmus Lerdorf’s localhost. Still, for a little Home Page script, it has grown into something that is now used on over 200 million websites around the world. That is nothing to be scoffed at. In this article we’ll discuss the two most important things we should try to remember when developing in PHP.
While we all know that PHP is not perfect, I seriously doubt that anything can be done about that right away. That said, there are not many languages that can run pretty much the same in version 6 as they could in version 3 (Yes, I did read what I just said, and I have an old php3 script that still runs on PHP 5, and should run on PHP 6, ok? Ok.) Development in PHP is always a tricky road to follow considering that you are developing something that will not usually run on a server that you have real control over–unless you are lucky enough to be able to afford your own server–and be viewed on a multitude of browsers that all display elements differently, anywhere in the world, over a connection that is usually shakey at best.
Knowing all of this, what are the two most important things we should we try to remember when developing in PHP?
1. Develop On Linux.
This is not really a RULE, but it is pretty cool to know that the server on your laptop or home pc is actually set up exactly like the server you are going to run your application on. The reasons? Quite simply, you will be developing on a local server (localhost) that is usually Windows-based, right? And when you deploy your application / website, it is going to run on a Linux server? The semantics might not mean anything to you, but what is important is that Windows-based servers are not really case sensitive. In other words, you could have a url like http://mysite.com/folderName/ when you set up your website on your Windows localhost. Mostly you might think this looks cool. So you set up all of your links like that, and everything is just perfect. Then off you go and upload your site to your webserver and…well, the link does not work, even though you have tested everything a million times. I promise you–because I have done it–that you will not think about the capitalization the first time it happens to you. Trust me. All you get is a “page not found” error even though you know the page exists. Frustrating and time killing if you have more than ten links on your website.
Besides that, Linux is a very stable environment to develop on. Our company development server is an Ubuntu-based OS that runs 24 hours a day, 7 days a week, and has never, ever been shut down or turned off in the last four years. In that same time it has never crashed or frozen. To me that is respectable.
If you are really unable to tear yourself away from Windows, you need to try to get your development environment setup to mimick Linux as best you can. That way you will have less surprises when you upload your application to its production server.