Node.js vs PHP?

dimensionav used Ask the Experts™

I'm now checking node.js as an oportunity to create webapps with my clients, but I have this doubts that I need to solve:
-Is node.js faster than PHP, ruby or Python? (I've already seen some performance benchmarks between these three, but i only want to confirm it).

-How about security? I've heard that there are some security problems with the sockets and the protocols that node.js uses

-Is there any good framework for node?

-Does Laravell, CodeIgniter or any other PHP framework can be a better option than node.js?

-Is there good support in hosting servers for it?

Any other comments of this topic are welcome.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
I've used Laravel for the server application and AngularJS for the client side.  This was a good combination, but AngularJS has an awkward learning curve -- you feel like things are great, then they are not, then they are, etc.  It's very easy to find best practices for PHP, but not so easy for AngularJS.

On the PHP side, I would not consider any framework other than Laravel.  It's a Lamborghini and everything else is a second-rate choice in comparison.

Ultimately the best framework / platform is the one you already know, so consult with your developers and work with their preferences!
Top Expert 2015
You need to understand how your technology is going to be used to determine which might be best suited. For instance. PHP is a top-down, left to right language that begins and end like nothing happened before it is invoked each time it runs. There is no persistence in the language's interpreter, therefore it relies on external storage and lots of logic to be written in verifying that it doesn't go left when you want right simply due to your forgetting or missing a check. It starts, finishes and repeat the lifecycle. The usage is simply to dynamically manipulate output, and if that output is HTML, then there's your webpage. If it's CSS, then don't expect your browser to interpret the correct mime type unless your request is of that type, or your headers are set within PHP appropriately. It's all backend.

Node.js is a frontend Object Oriented framework that is meant to connect applications and maintain the connection to the backend code, without having to make each request individually like ajax or standard requests. It can increase the speed and efficiency of your application on the frontend, but you have no control over the code on the users end if they manipulate it, so if a persistent connection is required or benefits your application, then you might consider using it. Otherwise it's a waste to go through putting it and a full backend in and not really needing it. Javascript is your prewritten code executed on the client end for the purpose of UI/UX and offloading things that your backend doesn't need to see in order for the user to complete their transaction. For instance, if you need text in a field, and they forgot to input it, why make your backend server, the internet, the browser, and user all go through the motions when validation can be handled on the user side before it is submitted and told to do it again. Node, expands on that and again is like Angular.jS in it's purpose and intentions in relation to usage.

Ruby is great, but understand that without the rails framework, you might as well not for the web in my opinion. It can be deployed through the browser in a more secure way than Node and other Javascript which relies on you understanding that the security hole is presented to the user and it should be addressed. Usually when ruby is written. from what I've seen, it's a complied app like java beans to the browser the user can't change, but connects persistently like node does and PHP can't, while eliminating the security concerns of exposed source code on the user's system. It can be faster, and could be slower depending on what you tell it to do and how you want it to work.

Overall performance can be better or worse with certain languages depending on how you write it. If you can write the same thing 10 ways with less memory and cycles in PHP, but use the wrong one, then a crappy app is your fault and not the languages in terms of performance.

Node.js is a framework for JavaScript. I wouldn't use multiple frameworks for a single project in the same language unless you really want to feel intimate with the code and how it works.

Ruby and JavaScript are Object Oriented. PHP can sorta be, but it isn't. starts, finishes, and GOTO is the closest thing it has in really making it not care about starting at A and ending at Z. It's getting better, but will never be OO truly like Java or Javascript or Ruby.

Python is basically the dip your toes in the water but you're hesitant to fully dive into Ruby and Node style applications. I don't see it used outside the XML-RPC style apps which can be extremely overly complicated for their purpose, and SLOWWWWW compared to all your other options. It's more similar to PHP than Node and Ruby, but closer to Ruby than PHP. If you don't have a choice, get ready to feel like you had to move a boulder to cover a mousehole, and when you see how other languages handle the same tasks, you probably will steer away from python. I did, and out of all the 15+ languages I've used and know, it gives me the biggest headache and I don't fully think it has any compelling reason to make me want to use it over another language.

Laravel i don't like in terms of syntax. It gets ugly quick while starting out pretty. CodeIgniter is great in my opinion and performance is a big thing they keep in mind when it is maintained. Bloated only comes from you, at that point. They have a couple PHP CI and AJAX RESTful API style apps out there like my personal favorite in terms of them all - CJAX:

Great prebuilt examples, even though they don't look pretty. You can fix that with your app.

My personal all time non bundled way of doing is is with CodeIgniter, and a AJAX framework for HTML5 called Intercooler.js .. You use HTML5 attributes and it handles the JavaScript in a super simple way allowing you to focus on the backend response. Check out the examples:

I had it up and integrated in applications within 5 minutes.

Overall, your decision, but I would stick to what you find easiest, and if you're looking for frontend user experience with the least amount of effort, look into React and the React-Magic framework for a drop in instantly smooth similar outcome found here:
Automatically AJAXify plain HTML with the power of React. It's magic!

Essentially it calls out the A link you clicked on capturing the request, comparing the returned HTML to the existing DOM HTML, and only updates the modified elements leaving everything else in place, with no configuration required for it to work immediately.

Hope this helps!
Top Expert 2015

Oh with intercooler, if you want to use it for notifications on updates and such, you might want to create a dummy <div> as a bucket at the end of your code and empty, then replace it with javascript that will modify it to flash/update the results of your POST or other REQUEST with ease.
Top Expert 2015

Oh yeah, the latest trend in languages I have seen are PHP code backend systems which use the JIT (java just in time compiler) to compile your code into C extensions making it blazingly fast over what it is as the interpreted script code which is done by a precompiled C application (php.exe or php binary on your system - *nix won't use exe php binaries). Check out starting with Phalcon, HHVM or PHPNG if you want to go that route. Seems awesome to me, and lots of benchmarking. Another thing to think about is your Webserver engine. nginx is typically faster than Apache, but apache can be easier to understand and use, while comparable in speed if you do it correctly, e.g., don't use htaccess,  but instead write the rules in a configuration file. It doubles the speed. - PHP creators trying to keep up with the above style implementations.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial