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

Nested callbacks naturally allows for non-blocking code, which leads to higher request capacity.

In, say, Ruby, you've got EventMachine for something equivalent but it's definitely "bolted" on to the language. Python has Twisted, with which I have no personal experience. In PHP, there are really no options.




If it's about higher request capacity, PHP scales horizontally with its share nothing, no application server architecture. I'm not advocating, just sayin'.


Nonblocking IO doesn't preclude horizontal scaling.

The Node / EventMachine / Twisted version of nonblocking IO is built on the Reactor Pattern. The common use case is to minimize IO delay. Whenever there is IO, a NodeJS script will cheerfully continue execution of other code, whereas in PHP and other purely synchronous languages, the script would block while waiting for the result. In practice, this has more use cases than just IO, of course. For example, one can send heavy computations to background processes and execute other code while waiting for the result.

So back to the original point, yes, writing nested callbacks can be more difficult to decipher than "flat" code, but the results may very well be worthwhile if you are looking to squeeze maximum performance out of your hardware.


For example, one can send heavy computations to background processes and execute other code while waiting for the result

That you can actually do in PHP, for example with gearman:

http://docs.php.net/manual/en/gearman.examples-reverse-bg.ph...




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: