Live data from Hacker News

Benchmarking Codswallop: Node.js vs. PHP

philsturgeon.co.uk

21–30 of 85 posts

Re: Benchmarking Codswallop: Node.js vs. PHP

#22
post #19

Long term php guy (I maintained APC for years, slowly given up now), so I've worked a lot with ~2k/3k request-per-second PHP websites. The real trick here is async processing. A lot of the slow bits of PHP code is people not writing async data patterns. If you use synchronous calls in PHP - mc::get or mysql or curl calls, then PHP absolutely sucks in performance. Nodejs automatically trains you around this with a mas…

What are best practices for writing async code in PHP?

Re: Benchmarking Codswallop: Node.js vs. PHP

#26
I've made a similar observation to the original post — in my case, moving a bit of functionality from PHP to Node.js gave me 100x better performance: https://servercheck.in/blog/moving-functionality-nodejs-incr...

But the reason for this wasn't that Node/JS is faster than PHP; it was because I was able to write the Node.js app asynchronously, but the PHP version was making hundreds of synchronous requests (this is the gist of the OP).

The issue I have is that Node.js makes asynchronous http calls relatively easy, whereas in PHP, using curl_multi_exec is kludgy, and few libraries support asynchronous requests.

The situation is changing, but the fact remains that asynchronous code is the norm in Node.js, while blocking code is the norm in PHP. This makes it more difficult (as of this writing) to do any non-trivial asynchronous work in PHP.

Re: Benchmarking Codswallop: Node.js vs. PHP

#28
I'm sick of all of these generic SPEED benchmarks. Let me tell you some BIGGEST & REAL benefits of NodeJS where PHP SUCKS.

1. Takes 1 minute to install on any platform (*nix, windows etc.)

2. A modern Package Manager (NPM) works seamlessly with all platforms.

3. All libraries started from 0 with async baked in from day 0.

4. No need to use any 3rd party JSON serialize/deserialize libs.

5. And above all, its Atwood's law

"any application that can be written in JavaScript, will eventually be written in JavaScript".

http://www.codinghorror.com/blog/2009/08/all-programming-is-...

Re: Benchmarking Codswallop: Node.js vs. PHP

#30
post #5

Node benchmark is flawed though. Add something like require('http').globalAgent.maxSockets = 64; at the top of node script if you want a fair comparison with async php version. The bottleneck is bandwidth here. Not the runtime. On my laptop, original script from the author took 35 seconds to complete. With maxAgents = 64, it took 10 seconds. Edit: And who is downvoting this? I just provided actual numbers and a way t…

Nobody should be downvoting you, you raise an excellent point and you are of course right.

NodeJS v0.10.21 + Cheerio

real 0m47.986s user 0m7.252s sys 0m1.080s

NodeJS v0.10.21 + Cheerio + 64 connections

real 0m14.475s user 0m8.853s sys 0m1.696s

PHP 5.5.5 + ReactPHP + phpQuery

real 0m15.989s user 0m11.125s sys 0m1.668s

Considerably quicker! As I said I was sure NodeJS could go faster, but the point of the article was that PHP itself is not just magically 4 times slower, it is in fact almost identical when you use almost identical approaches. :)

Post reply on HN