my name is nathan nobbe. over the past few months i have converted the existing php puremvc port down to a native php extension. ill get to the details, but first the fun stuff, performance. the below numbers are average requests per second on my test box:
(note: these are only preliminary results)
static html: 588.69
native extension: 404.67
php (opcode caching on): 248.15
php (no opcode cache): 122.61
so right off the bat you can see its extremely fast
i generated these numbers by taking the php port, loading up the demo site, and first taking the output to create the fully static index page, which is the baseline. then used apache bench to test the 4 variations as they loaded the index page of the demo site.
im not sure where to go from there really, so please bear w/ me. i started out doing this, b/c ive been trying my hand at php framework authoring for a while, ive not yet liked anything ive made too much, but then i saw the spec for PureMVC. the idea is to boil down PureMVC to native code (as i have) and then build the rest of the application framework around it, using best-of-breed, off-the-shelf components (eg. smarty, propel, inspekt, etc.) my viewpoint is that PureMVC has the makings of a sort-of kernel for application frameworks. well, what we have on our hands now, simply put, is the fastest mvc available anywhere in the world for php! whats even better, since the userspace php version is already out there, people can run apps built on PureMVC on shared hosts that dont want to install the extension, which is a huge selling point.
ok, enough about the stupid storyline.. more about what ive done... so i just downloaded the php version of PureMVC and went through, line by line, converting it to a native extension. i wrote my own unit tests using .phpt, b/c thats how tests are typically written for native php code. and i wont lie, i didnt realize there were PHPUnit tests already provided until i was nearly finished
anyway, my extension is now passing all of my unit tests AND all of the PHPUnit tests that ship w/ the php puremvc system AND loading the demo site; so its pretty legit.
that being said, i have found a few things i would like to discuss regarding the existing implementation (which i will present in a more formal manor once ive had time to assemble a clean list) however, at a high level these issues are:
- a couple of api usage discrepancies
. i think these were mainly w/ the ::registerCommand() series of methods. you can see in the library a string is expected for the second arg, however, in the unit tests and in the demo site, objects are being passed.
- little to no error checking.
. there are several places in the code that could benefit from error checking. most notably, attempting to invoke methods on objects, when the methods may not exist on said objects. and to a lesser extent, checking to see if array keys exist before attempting to access them. as it stands the code is set to throw fatals and warnings pretty readily w/o library users implementing checks themselves.
- performance considerations
. several places in the code will create new object instances, by using the name of a class stored as a string, to get the class definition and then invoke the constructor. reflection has been used to implement these sections, and im left thinking how much faster it would be to just use the variable function feature of php, and let the engine look up the class definition. eg.
$class = 'MyMediator';
$mmInstance = new $class();
- a couple of other little things, like using toString() instead of __toString() for the Notification class, and what-not.
other than that, everything looks pretty solid. as i said, i will formally list out the suggestions/patches i have for the existing code w/ justifications, and im looking forward to the discussions and decisions (if any) to follow. i have versioned everything, and i have patches for both the php implementation of PureMVC as well as the PHPUnit tests. hopefully we can meet in the middle somewhere for the benefit of the php PureMVC user base.
one of my goals is to keep the extension as an identical port of the userspace code for multiple reasons,
- i want it to still be a legitimate candidate as an official PureMVC port
- the shared hosting thing is huge, not many native libraries offer a userspace counterpart, and now we already have that, making the case for this library very strong
my future plans are to add multi-core support to both the userspace and native libraries, then to branch for 5.3 and namespace all the classes. the extension will get an ini value to toggle it between single and multi-core. ill also be extending the existing unit test suite to handle the multi-core components of the framework. i can fork my work if necessary, but id much, much rather work w/ the fine people in this community to get the work accepted here as official. also, at some point i want the extension hosted on pecl.php.net, but ive already met w/ disregard by those folks. so ill have to ramp it up on the other side of the universe, then take it back to their court once its gained some momentum.
ill get the code up on the web sometime before end of next week, promise
. im using git these days, so ive been thinking to put it all up on github (been waiting to try that out).
at this point id like to thank Cliff, Omar, and Hasan for their work, as they have made mine possible. i look forward to meeting and working w/ the people in this community and really ramping this thing up!