Multi-directional analysis of the contention of PHP vs Node.js

Source: Internet
Author: User
Tags html form mixed php and mysql browser cache drupal
the "editor's note" PHP vs Node.js has a long history of being used for dynamic web development, which is the JavaScript toolkit for writing high-performance Web servers. Peter Wayner of the InfoWorld Test center recently wrote about the advantages of both, and it's worth a look.

The following is the translation:

This is a typical Hollywood plot: The battle between the two old friends who have parted ways. Friction often begins with one who is interested in another self-evident field. The programming language version of the film is the introduction of Node.js, which turns a friend's plot into a match. PHP and JavaScript, two of partners who once ruled the Internet are now starting to showdown the share of developers ' minds.

In the past, their partnership was simple. JavaScript handles small details on browsers, and PHP handles all server-side tasks that exist in port 80 and MySQL. This happy union continues to support many key parts of the Internet. On WordPress, Drupal and Facebook, people hardly ever leave PHP for a minute.

But later, some smart kids find that he can make JavaScript run on the server. Suddenly, we found it unnecessary to use PHP to build the next generation server stack. A language is sufficient to establish node.js and run the framework on the client. For some, "JavaScript is everywhere" becomes a mantra.

Of course, the ending has not been finished. Compared with the simple programmers who boast about Node.js's sheer and JavaScript ubiquity, there are other programmers who are satisfied with the depth code base and the stability of the PHP. Strange old man can repel the upstart on the server side. Can JavaScript overthrow its old friends and achieve domination of the world? We'll grab another popcorn in the microwave and sit down and see.

where PHP wins: mixed-content Code

You are typing, and the idea becomes the text in your website. You want to add a branch to the process, depending on the URL's parameters, a little if-then statement will make it look beautiful. Or maybe you want to add text or data from the database. With PHP, you can open the PHP magic tag and start coding in seconds. No template required--everything is a template. No extra files or painstaking architecture is required, because the programmable logic energy is at your fingertips.

where node wins: the content of the separation

Mixed-content code is a crutch that will eventually hurt you. Of course, in the first two or three times, mixed HTML code is interesting. But soon, your code base is mess. The real programmer adds the structure, separating the decorative layer from the logical layer. For new programmers, the code is easy to understand and easy to maintain. The framework that runs in Node.js is built by such programmers who know that life can be better when models, views, and controllers are separated.

Where does PHP win: A deep code base

The web is full of PHP code. The most popular building site platforms (WordPress, Drupal, and Joomla) are written in PHP. Not only these open source platforms, most of their plug-ins are also written in PHP. There's PHP code all over the Web, and it waits for you to download, modify, and use it for you.

where node wins: New code means more modern features

Of course, there are thousands of open source PHP files on the web, but some are 8-year-old WordPress plug-ins hoping and praying for someone to download them. Who wants to spend hours, days, or weeks trying to pick up code that hasn't been updated in years? Node.js Plug-ins are not only new, but are built with the full knowledge of the latest system.

Where does PHP win: simple (to some extent)

There's not much in PHP: several variables and basic functions that handle strings, numbers. It does not do much except move data from port 80 to the database and return. This is what should be done. Modern databases are a magical tool that can get away from heavy loads. The complexity of PHP is moderate in that it should not be complicated.

where node wins: Closures and more complexity

JavaScript may have many small qualities that drive some people crazy. But in most cases, it is a modern language for entertaining modern grammar, with several useful features, such as closures. You can easily reconfigure and expand it to make a powerful library of functions like jquery possible. You can pass functions around like passing objects. Why do you limit yourself?

Where does PHP win: No client application required

All the discussion about using the same language on browsers and servers is good, but if you don't need to use any language in your browser. If you ship the data in an HTML form. The browser pops up and does not cause headaches and glitches caused by an open JavaScript attempt to create a page from more than 20 Web service calls on the browser. Pure HTML works more often than anything else, and PHP is optimized to create HTML. Why bother using JavaScript in the browser? Set up all operations on the server to avoid small browser overloads on small phones.

where node wins: A thin service call relative to the Html-fat PHP call

Although Ajax-crazy HTML5 Web applications have many moving parts, they are cool and very effective. Once the JavaScript code is in the browser cache, the new data moves along the line. This does not have a large number of HTML markup Language, do not repeat to download the entire page. Only the data has changed. If you are willing to devote time to creating a smooth browser-side Web application, this will be a good reward. Node.js is the most optimized way to transfer data, only data through Web services. If your application is complex and data-rich, this will be a good basis for effective delivery.

where PHP wins: SQL

PHP and MySQL and many of its variants, such as MARIADB. If MySQL is not all right, there are other great SQL databases from Oracle and Microsoft. Your code can be converted into your query with little change. The vast world of SQL has no boundaries. Some of the most stable, mature code is connected to the SQL database, which means that all the power can be easily integrated into the PHP project. It may not be the perfect happy family, but it is big.

where Node.js win: JSON

If you have to access the Sql,node.js library you can do it. But Node.js also has JSON, a common language that interacts with many of the newest NoSQL databases. This is not to say that you can't get a JSON library for your PHP stack, but some fluids can be used with the simplicity of JSON when using JavaScript. This is the syntax from the browser to the Web server to the database. The colon and the braces are the same in every place, which saves you time.

Where does PHP win: Coding speed

For most developers, writing PHP Web applications feels faster: No compilers, no deployments, no jar files or preprocessor-just your favorite editor and some PHP file directories. Your progress will be different, but with the quick identification of the project, PHP is a very useful tool.

where Node.js win: Original speed

In the process of writing JavaScript code, when you are calculating curly braces and parentheses, it is a bit difficult, but after writing successfully, your node.js code can fly. Its callback mechanism is ingenious because it saves you the time to run the thread. The core is built to do everything for you, that's not what everyone wants.

Original link: PHP vs. Node.js:An epic battle for developer Mind Share (Translator/Shongxia Zebian/Chang)

This article for CSDN compilation, without permission not to reprint, if need to reprint please contact market#csdn.net (#换成 @)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.