Hacker News new | past | comments | ask | show | jobs | submit login

are you using a custom PHP framework to get your bootstrap below 20ms ? would like to hear more about your stack setup to get that kind of performance

I have to admit our architecture is unconventional. It's custom code except for a few ZF1 parts like zend_db, zend_json_service and zend_validate. Even our session and auth code is all custom. The server we use is zend server (with zend opcache). We only have web services on the server, it's a javascript ui.

The web service wrapper on the server has been cut down to the essence and does not use autoloading for the basic bootstrap. I've found that the PSR approach of a gazillion files each containing a small class and liberal use of autoloading is inherently slow, it is death by a thousand paper cuts due to the high degree of file access, memory consumption and running of all that constructor code. The code i write typically groups a web service in a handful of files, each containing a namespace with the bulk of the implementation in procedural logic (though i do use closures quite a bit). I typically use classes / objects only as types that encapsulate data, with the logic on the object limited to that logic which is necessary for working with that type (e.g. I don't put a save method on an object but instead write a saveObject function which accepts the object as a parameter and passes back an array of errors).

I suppose a lot of people nowadays find that sort of coding style blasphemous, but it is easy to write, test and maintain, and fast to execute. I'm not against the heavy OO approach common in most web dev nowadays, there are times when i do use it and need it. But CRUD web services are very linear: validate the input, create a transaction, run a bunch of db operations, commit or roll back, and return status / errors. If something is linear, i prefer to see it implemented in a cohesive linear procedural style, instead of getting chopped up into lots of objects that in practice end up obfuscating what's happening.

Thanks for sharing this. It's interesting that you can improve your performance so much by, essentially, getting rid of the automatic class-loader. On the other hand, the autoloader is one of the most important improvements to PHP in the last couple of years. It looks like PHP's recent improvements -- easier testing using dependency injection, ORMs, class loaders -- all have a pretty big cost in terms of performance.

Thanks for sharing your approach. would love to see maybe an open source version of your framework to use a starting point. I am starting work on customizing CodeIgniter to be slim framework for serving a REST API, and your approach is going to be super helpful to learn from :)

The only thing i can point to is my metaprogramming experiment: https://github.com/jsebrech/php-o

The way of initializing and validating data objects is quite similar to the approach we have in our production code. The missing part is the web service layer that maps the type definitions to a service description (i use reflection of phpdoc comments on a web service class to generate json and soap bindings, similar to the reflection approach in that github project).

I've been meaning to pick it back up and implement both the web service and db layers to make it an all-purpose web dev framework, but i've had other side projects intervene.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact