Prerequisites: apache with mod_rewrite and mod_fcgi, shell access (maybe root/sudo)
UBUNTU USERS - READ THIS FIRST!!
You might think compiling PHP, a scripted language, is a bit daft, but there are a few really good reasons you might want to compile your source code. In fact, compiled web code has been around for a while now, what with ASP.NET and all that. The main two reasons are (1) protecting your intellectual property if your project is closed-source and (2) potential speed increases. I say potential because that’s just a theory really - I’ve not investigated speed increases (or even decreases) yet, all I’ve done is compiled a test app and got it working.
I used Ubuntu as my compilation OS, because… well it’s awesome really*. I used this and this as the main guide, so read them and I’ll skim over the process I did here.
Read the rest of this entry »
Opening up Google Reader this morning, I found this post on PHPDeveloper.org’s RSS feed. They use Xen hypervisor on their big beefy servers to provide what they call “slices” (i.e. virtual machines that you can do pretty much whatever you want with).
The host is called Slicehost, and the provide VMs of 256mb RAM up to 15.5GB RAM (!). Prices for the smallest “slice” is $20 (£13.37) per month, which is pretty reasonable for the muck-around equivalent of your own dedicated server. The beauty of it is that the resources you pay for are reserved, so you won’t find some other “slice” on the same server as you using up your RAM or CPU time when you need it the most. Of course, these VMs aren’t just limited to development servers, upwards from the 1GB slice is the equivalent of your own dedicated server, so is also more than suited to production servers, especially as initially Slicehost was meant for business and production needs. Bandwidth is pretty reasonable as well - 100GB per month for the base package. Personally I wish something like this had come along before I bought 1and1 hosting for 2 years, heh! Oh well.
Check out Slicehost here!
Got this from Daniel Pope’s blog…
- Grab the nearest book.
- Open it to page 56.
- Find the fifth sentence.
- Post the text of the sentence in your blog along with these instructions.
- Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.
Similarly, a class that wraps an HTTP request (including headers, response codes, and so on) has only one instance per request.
The book that was nearest to me was Advanced PHP Programming by George Schlossnagle (ISBN 0-672-32561-6).
I posted this a few days ago, inspired by David Otton’s post on this topic. A chap called Will commented about it, and after doing a quick Google, I got angry and realised how* many people are misinformed that stdClass is the base PHP class for everything.
As of the latest stable release of PHP, this is not the case. And it bugs me when people say “stdClass is the base class of everything in PHP”. stdClass is actually just a basic object with no methods or properties that you can use however you wish. A common use is to create a quick on-the-fly object, e.g.:
$obj = new stdClass();
$obj->Name = 'foobar';
$obj->Id = 24;
$json = json_encode($obj);
As you can see, $obj in this context is throwaway and is just used and forgotten about. I’ll re-iterate what David Otton says about it, and is quick and simple proof:
class DoesNotExtend {};
class DoesExtend extends stdClass {};
$doesNotExtend = new DoesNotExtend();
$doesExtend = new DoesExtend();
var_dump($doesNotExtend instanceof stdClass);
var_dump($doesExtend instanceof stdClass);
Outputs:
bool(false)
bool(true)
So please, when someone asks “what is stdClass” etc., don’t say “Oh, it’s the base class for all objects”, because it bloody well isn’t.
* Jaxxed seems to be slightly more well-informed, but that post was back in 2005. Since then, PHP 5 has come out, and classes are implemented much better. He’s still wrong though, it’s not the base class.
As David Otton points out, PHP is different from most other OO languages such as Java, or even Delphi, in the fact that most languages have a base class that all other classes inherit. Indeed, stdClass is not the base class for everything - it is in fact just a backup in case PHP doesn’t really know what class it is - it’s basically just a generic class.
After having used Netbasic’s custom MVC for several months now, which has a base class, I believe there can be merits, especially in a framework situation, to extending a base class such as Object throughout all classes. You can add things like debug code into Object, and it propogates through into all child objects. It’s sometimes a good idea to take this ethic further, such as in .NET, classes are arranged from parent to child according to how specific their function is… i.e.
- Object - base object
- Control - a generic control
- WebControl - a generic web-based control
- BaseDataBoundControl
- DataBoundControl
- ListView - the list view object
I suppose how your classes are structured should be dictated primarily on what your application requires, and secondly on how you like them structured… it’s preference at the end of the day!