Home  >  Article  >  Backend Development  >  PHP vs. Nodejs: An epic battle over developer preferences

PHP vs. Nodejs: An epic battle over developer preferences

WBOY
WBOYOriginal
2016-08-08 09:22:29734browse

PHP vs. Nodejs: An epic battle over developer preferences

The whole story is just like the classic plot trend of Hollywood blockbusters: two former friends have now parted ways, and are even forced into a life-and-death struggle. The disagreement at first was not serious. It was simply an old friend becoming interested in a business area that the other partner had long occupied but never talked about. In the real-life version of this programming language duel movie, Node.js became the trigger for the good brothers to turn against each other, and this triggered an evenly matched battle: PHP and JavaScript. They worked together to rule the entire Internet world, but now they are killing each other in order to compete for the support of developers.

Thinking back to those days, cooperative relationships were always simple and pure. At that time, JavaScript took care of the details on the browser, and PHP managed all the server-side tasks that existed between port 80 and MySQL. At that time, the two parties maintained a happy cooperative attitude and continued to provide support for various key components of the Internet. Whether it's WordPress, Drupal or Facebook, without PHP, people can hardly stay on the Internet for a minute.

However, a clever technician discovered an amazing secret: JavaScript can also run on the server. Almost overnight, it seemed that we no longer needed the power of PHP to build the next generation of server stacks. With just one language, we have been able to build Node.js and various other frameworks that run on the client. "JavaScript is everywhere" has even become a working belief for some developers.

Of course, the ending of this story has not been finalized yet. For every developer who preaches the advancement of Node.js and the convenience of JavaScript, there are always those who oppose him-they prefer PHP's deep code foundation and long-term stable actual performance. So can this old ruler defeat the challenger on the server home court that he has occupied for many years? Will JavaScript ruthlessly overthrow its old friends and realize its ambition to unify the world? Please pick up the popcorn buckets and Cokes in your hands and watch this exciting show of roommates having sex together.

PHP wins: Mixing code and content

During the input process, of course everyone hopes to convert their ideas directly into the text content of the website, and at the same time add branches and part of if-then to the process statement to ensure that the site has beautiful visual effects, depending on certain parameters in the URL. Or, we want to be able to mix text or data using a single database. With the help of PHP, you only need to open the magic PHP tag and start writing code within seconds. Yes, no templates are needed - everything is already templated! There is no need to use additional files or complex structures. The power of programmable logic is at our fingertips, waiting for you to use it.

Node.js wins: focus division

Mixing code and content is like a magic crutch. Although it can guide users well at first, it often becomes heavy in the end. burden. Granted, mixing code with HTML can be quite fun—at least the first few times you try it. But many of our code bases become a mess of mixed logic. Real programmers add structure to it and separate the decorative layer from the logical layer. Obviously, novice developers can have a clearer understanding of the project, and it is easier to complete subsequent maintenance work. The various frameworks that run on Node.js are built by a group of programmers who know that life will be better when models, views, and controllers are clearly separated.

PHP Wins: Deep Code Base

The entire online world is filled with a lot of PHP code. Various mainstream platforms used to build websites (including WordPress, Drupal, Joomla, etc.) are written in the PHP language. In addition to these platforms, most related plug-ins also exist in the form of open source code. All in all, PHP code is readily available, waiting for everyone to download it, modify it, and use it as needed.

Node wins: new code means modern functions

It is undeniable that thousands of open source PHP files can indeed help everyone complete project development more easily, but many of them have reached eight WordPress plugins that are 10 years old are waiting and waiting for developers to download them and use them. Who wants to spend hours, days, or even weeks debugging code that hasn't been updated in years? At least I don't want to. Node.js plug-ins are not only younger, but also enjoy all the conveniences brought by the latest architectural solutions. The programmers who developed this part of the code knew very well that modern web applications should introduce more intelligent elements to the client.

PHP wins: convenience (more or less)

There is not much to say about the use of the PHP language: a few variables and basic functions composed of strings and numbers are everything. This is a very focused solution, and all users expect is to use it to move data from port 80 to the database and backend. PHP does not have much ambition, it is its bounden duty to be able to complete this task well. Modern databases are miraculous tools, so we can hand them over to handle all kinds of heavy workloads. PHP is a moderately complex processing method, and there is no need to make it difficult to use.

Node wins: closure complexity, etc.

Some small awkwardnesses in the use of JavaScript may drive some developers crazy, but overall it is a modern programming language, among which Contains a large number of modern syntax plus a series of practical features represented by closures. It can be easily reconfigured and extended, making powerful libraries like jQuery possible. We don't need to worry about functions like objects. Why do you have to struggle with yourself?

PHP wins: No client application required

Everyone says that if the same language can be used on the browser and server, the actual effect will definitely be the best. But wouldn’t it be better if we didn’t have to use any language in the browser at all? What if we could directly implement data output in HTML format? The browser can accept this data directly without the hassle and glitches caused by a JavaScript thread trying to create a page on the browser using dozens of web service calls. Pure HTML often performs better than other forms, and PHP is fully optimized for such creation tasks. Why bother introducing JavaScript into the browser? Building everything on the server and trying to avoid leaving too heavy tasks to the small browser on the small phone is the right solution.

Node Wins: Service calls are leaner than bloated PHP HTML calls

Although AJAX often crams a lot of moving parts into HTML 5 web applications, they are really cool - and powerful Effective advantages. Once the JavaScript code is in the browser's cache, all that's left to travel back and forth over the network wires is new data. Here we don’t have to deal with tons of HTML tags, and we don’t need to download the entire page content repeatedly. Only the data within it will change. If you are willing to take the time to create an exquisite web application, then it will definitely bring you ideal returns. Node.js is deeply optimized for the data delivery mechanism, and data only needs to be provided to web services. If your application is very complex and full of large amounts of data, then Node.js will undoubtedly establish a good foundation for the effective transmission of information.

PHP wins: SQL

PHP’s design itself takes into account the need for coexistence and collaboration with MySQL and its multiple variants, such as MariaDB. If MySQL is not enough to meet your actual needs, there are more other excellent SQL databases from Oracle and Microsoft for us to choose from. Our code can be converted into query instructions through simple activation. The vast world of SQL is endless, and its territory is still expanding. Quite a few of the most stable and highly developed codes will be connected to SQL databases, which means that all these powerful capabilities will eventually be easily integrated into PHP projects. Perhaps the entire ecosystem cannot be called a perfect and harmonious family, but its considerable scale cannot be denied.

Node.js wins: JSON

If you must access SQL, then Node.js also provides related libraries to complete this task. But in addition, Node.js can also interoperate with JSON. This universal solution can interact with many of the latest NoSQL databases. This is not to say that we can't get a JSON library in our PHP stack, but when using JSON with JavaScript, it can often lead to simple and convenient task processing processes. In this way, we can ensure that the same syntax is used from the browser to the web server to the database, in which colons and parentheses are used in exactly the same way and function. This will help everyone save development time and significantly reduce frustration when writing code.

PHP wins: coding speed

For most developers, writing web applications in PHP can often lead to a more efficient coding experience: no compiler, no deployment, no need to Provide a JAR file or pre-processing mechanism - just use your favorite editor and some PHP files in the directory, and the development work will be easy. Your actual development process may be different, but when it comes to a magic weapon for quickly completing projects, PHP definitely plays its part in this internal fight.

Node.js Wins: Raw Speed ​​

If you look at the number of braces and parentheses in the code itself, it is indeed more difficult to write JavaScript code, but after the development work is completed, the running speed of the Node.js code is extremely amazing. The introduction of the callback mechanism is a genius move, because it can greatly save us time in dealing with different threads. The core of the code is well built and specifically designed to achieve what we actually need. Isn't this what every developer dreams of?

English: http://www.infoworld.com/article/2866712/php/php-vs-node-js-an-epic-battle-for-developer-mind-share.html

The above introduces PHP vs. Nodejs: an epic battle about developer preferences, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn