Multi-faceted Analysis of PHPvsNode. js contention

Source: Internet
Author: User
Tags drupal
[Editor's note] the battle for PHPvsNode. js has been around for a long time. The former is used for dynamic web page development, and the latter is used to compile a JavaScript toolkit for high-performance Web servers. What exactly do they do? Peter Wayner of the InfoWorld Test Center recently wrote an article about the advantages of the two. This is a typical Hollywood plot: Part Two

[Editor's note] PHP vs Node. js has a long history. The former is used for dynamic web page development, and the latter is used to compile a JavaScript toolkit for high-performance network servers. What exactly do they do? Peter Wayner of the InfoWorld Test Center recently wrote an article about the advantages of the two. This is a typical Hollywood plot: Part Two

[Editor's note] PHP vs Node. js has a long history. The former is used for dynamic web page development, and the latter is used to compile a JavaScript toolkit for high-performance network servers. What exactly do they do? Peter Wayner of the InfoWorld Test Center recently wrote an article about the advantages of the two.

The following is a translation:

This is a typical Hollywood plot: the battle between two old friends in different ways. Friction often begins with one's interest in another self-evident field. The programming language version of this movie is the introduction of Node. js, turning the plot of friends into a pretty big match. PHP and JavaScript, the two partners that once ruled the Internet, are now beginning to give up their share of the developer's mind.

In the past, their partnership was simple. JavaScript processes small details on the browser. PHP processes all server tasks that exist on port 80 and MySQL. This happy union continues to support many key parts of the Internet. On WordPress, Drupal, and Facebook, people almost never leave PHP for a minute.

However, some smart children later discovered that they could run JavaScript on the server. Suddenly, we found it unnecessary to use PHP to build the next generation Server Stack. A language is enough to establish Node. js and a framework running on the client. For some people, "JavaScript everywhere" becomes a curse.

Of course, the ending is not finished yet. Compared with simple programmers who boast about pure Node. js and JavaScript everywhere, there are other programmers who are satisfied with the deep code library and understanding of PHP stability. Can the strange old man beat back the new expensive server? Can JavaScript overturn its old friends and conquer the world? We grabbed another popcorn in the microwave and sat down.

Where PHP wins: mixed content code

Where Node wins: separated content

The code for mixed content is a cane, which will eventually damage you. Of course, in the first two to three times, hybrid HTML code is interesting. But soon, your code library was in a mess. A real programmer adds a structure and separates the decoration layer from the logic layer. For new programmers, the code is easy to understand and easy to maintain. The framework running on Node. js is built by such programmers who know that life will become better when models, views, and controllers are separated.

Where PHP wins: Deep code library

The network is full of PHP code. The most popular website platforms (WordPress, Drupal, and Joomla) are all written in PHP. Not only are these open-source platforms, but most of their plug-ins are also written in PHP. PHP code is everywhere on the internet, waiting for you to download, modify, and use it for your purpose.

Where Node wins: New Code means more modern features

Of course, there are thousands of open-source PHP files on the Internet, but some are 8-Year-Old WordPress plug-ins that hope and pray that someone will download them. Who is willing to spend hours, days, or weeks to roll back the code that has not been updated for several years? Node. js plug-ins are not only new, but also built with the complete knowledge of the latest system.

Where PHP wins: simple (to some extent)

PHP does not have many things: several variables and basic functions that process strings and numbers. It does not do much except to move data from port 80 to the database and return data. This should be done. Modern databases are a magic tool that leaves heavy loads. For PHP, the complexity should not be complex.

Where Node wins: Closure and more complexity

JavaScript may have many small traits that drive some people crazy. But in most cases, it is a modern language for entertaining modern syntax and has several useful features, such as closures. You can easily reconfigure and expand it to make it possible to use powerful function libraries like jQuery. You can pass functions around like passing objects. Why do you limit yourself?

Where PHP wins: client applications are not required

All the discussions about using the same language on the browser and server are good, but what if you don't need to use any language on the browser? What if you ship data in an HTML form? In the browser pop-up, there will be no headaches or faults caused by unstarted JavaScript. This JavaScript attempts to create a page from more than 20 web service calls in the browser. Pure HTML works more frequently than other things, while PHP is the best way to create HTML. Why bother using JavaScript in a browser? Create all operations on the server to avoid reload of small browsers on small mobile phones.

Where to win Node: thin service calls relative to HTML-fat PHP calls

Although AJAX-crazy HTML5 Web applications have many mobile components, they are cool and very effective. Once JavaScript code is cached in the browser, new data is moved along the line. This does not involve a large number of HTML Markup languages. Instead, you can download the entire page. Only data has changed. If you are willing to invest time to create a smooth browser-side Web application, this will be a good reward. Node. js is the most optimal way to transmit data, only through Web Services. If your applications are complex and rich in data, this will be a good foundation for effective transmission.

Where PHP wins: SQL

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

Where Node. js wins: JSON

If you have to access SQL, the Node. js function library can do this. However, Node. js also has JSON, a common language for interacting with many of the latest NoSQL databases. This does not mean that you cannot obtain the JSON library for your PHP stack, but some fluids can be processed with the simplicity of JSON when using JavaScript. This is the syntax from the browser to the Web server, and then to the database. Colons and curly braces play the same role in each place, saving you time.

Where PHP wins: encoding speed

For most developers, writing PHP Web applications is faster: no compiler, no deployment, No JAR files or pre-processors-Just your favorite editor and some PHP file directories. Your progress will be different, but PHP is a very useful tool to quickly determine the project together.

Where Node. js wins: original speed

When writing JavaScript code, it is a bit difficult when you calculate curly braces and parentheses, but after writing, your Node. js code can fly. Its callback mechanism is clever, because it can help you save the running thread time. The core is built to do everything for you. Isn't that what everyone wants?

PHP vs. Node. js: An epic battle for developer mind share

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.