10 Comparison challenges between PHP and Nodejs

Source: Internet
Author: User
Tags install node
: This article mainly introduces 10 comparison challenges between PHP and Nodejs. For more information about PHP tutorials, see. In the recent SitePoint PHP vs Node. js Smackdown article, Craig Buckler compared the two languages to determine which one is better in terms of coping with a series of 10 challenges.

Craig mentioned in his book that these comparisons always have some contradictions. As an interesting follow-up, we asked Bruno? Kvorc (PHP developer of SitePoint) and James Hibbard (a JavaScript developer of SitePoint) provide comments for each round.

Their detailed views are as follows...

First round: start

The challenge of Round 1 is to see how quickly you can build a "Hello World" page in each language. This includes the time it takes to build a server environment.

Craig estimates that PHP won this round in part because the language is "more conceptual" and "not so scary for new developers ".

Bruno:

PHP wins the "start" round simply because more hosts support this language, so it is very easy to start. This is easy to use and requires no additional work. If more hosts use the Node command line instead of the file upload method, and use a simple "reload app" key on the control panel, the two will be the same. However, in terms of the actual syntax for displaying things on the screen, PHP is simpler-especially for those who have no programming experience.

James:

When developing on a local machine, I did not see a big difference between the two. To run the PHP script on your browser, you need to install some server software. to run the Node script, you need to install Node, and it is best to install a web framework such as express. however, as Craig said, PHP is "more conceptual ". the entry threshold of Node is higher. There is no dispute over this.

Round 2: help and support

The second round will consider the difficulty of getting help and support in two languages. PHP has won this round, mainly because it appears longer.

Bruno:

Keep silence on this.

James:

I agree with this statement. Node is a new technology, so currently, there will be less help. However, this is not a problem when Node becomes more and more mature.

Round 3: syntax

The third round compares the difficulty of understanding the syntax of the two languages. Craig determined that this round of Node won.

Bruno:

I disagree very much. There are some strange examples in the PHP syntax, many of which have been fixed, and many of them will be removed in the new version. On the other hand, JS also has the "this" problem ~

I disagree with bullet 3 (you do not need to switch between client development and Server development when using js during development. The server environment and the client development environment are completely disconnected, and switching in the brain is still required. There are always some new syntaxes that you cannot use in the browser, and vice versa, so it is also a language switch to some extent.

Bullet 4 (understanding JS will make you more interested in using it), which I agree to in some way. I have been using JS and PHP for many years at work, and it takes longer to use JS, but I like it very little-although it is purely personal.

James:

I love JavaScript. I know it has its quirks, and I know for some reason that ECMAScript 2015 will be modified and bring some exciting new features to the language. JavaScript is powerful and flexible, and can adapt to many different programming styles. Compared with PHP, I enjoy using JavaScript. Node (Node. js) is one of them.

Round 4: Development tools

Round 4: considering the development tools used by these two technologies, Node is slightly better than Node because it has the development tool npm.

Bruno:

Although the developer was initially encouraged by npm, leaps and bounds are now more comfortable than npm, and if you have installed two versions of the same library on your computer, leaps and bounds won't crash your system. In addition, compared with npm, leaps and bounds allow designers to use recursive ideas, which are so important that when developers are preparing to establish a package manager, they should first consider this.

Npm has another fatal drawback. I call it "developer collaboration-friendly". npm cannot do this well. for npm, only developers can understand what they write. Finally, npm and Vagrant cannot be well compatible, which directly prevents you from starting your own work, let alone npm does not focus on users' needs. Npm has a bug that has existed for many years. it causes the software to be basically unavailable on windows, which is not a small problem. Of course, PHP also has many stupid errors, but these errors won't happen with your system.

Indeed, PHP does not have a built-in compiler, but I don't think it should do this. Such convenience should not be completed by a package manager or an independent application. If someone develops a good package manager for Node one day, it will be extremely difficult to replace it with the existing compiler. Make it relatively independent, and people can switch easily. In addition, you only need to enter a line of code on the terminal or download an installer.
The statement mentioned in the book that has little influence on compilers is an obvious mistake. Since the completion of PHP development, the compiler has affected every new PHP developer, and some of them have to add it to the existing process. It is only based on the reasons why many PHP users have existed before the compiler does not play a small role. In fact, it has had a huge impact since it was available. Some people say that "there is little impact on the community" and there is no factual basis.
Now, I cannot argue over the fact that most PHP developers want to install Node. Sadly, many good tools are first developed under Node, but I still hope that they can be used for BowerPHP development just like the Node-free development environment.

James:

I'm glad someone has joined Node.

I like npm. It is easy to install, easy to use, and has thousands of packages available for almost any need. I also like the fact that npm can select global and local packages (in contrast, some languages such as Ruby, its standard requires that your package be installed next to your Ruby version ). It also provides great tools. Some tools, such as Bower and Grunt, have a fixed position in my workflow, which doubles my work efficiency.
It is also worth mentioning that npm has developed version 3rd beta. It solves many problems mentioned by Bruno, such as the nested node_modules method error.

The following reference is from entire smackdown:

PHP developers may want (or need) to install Node. js on some occasions. This is not true.

Round 5: Environment

In the 5th round, we will talk about the availability and deployment of technologies, as well as the platforms and ecosystems that support them. Craig is not very clear about this, but it seems more inclined to be Node.

Bruno:

Craig said that he had compared the web advantages of PHP and Node (common web development problems), and then said JavaScript was used everywhere. First, compare Node. js, instead of JS itself. second, compare the environment in which the two languages can run. Monkeys are worse than fish because they are too stupid to climb trees, but both monkeys and fish can swim. Then let's compare how they are done.

In the web development environment, PHP won. Here are some PHP-based desktop tools -- yes, maybe you won't use them, but you will certainly use these PHP-based command line programs.

James:

Craig and I reached an agreement again. Some features make Node. js so popular (fast, scalable, closely connected to JSON, low resource usage) that it is suitable for many other types of applications, such as powerful IoT devices. I think, who will dislike robots?

Node improves the project, such as NW. js (an application based on Chromium and Node. js). it allows you to write local apps on HTML and JavaScript. This is exciting!

Sixth round: Integration

In the 6th round, let's take a look at the integration of databases and drivers. the reason for winning PHP is that it is older.

Bruno:

Integration is actually a draw. PHP has an age advantage and can have more options, but it also means taking care of a lot of outdated technologies, such as mysql expansion-we can upgrade to PHP7 to get rid of it, however, it has been unavailable for many years.

James:

Of course I agree with this point of view. although it seems vague, I like this example very much: "outdated, more popular technology ". This also highlights a great advantage of Node-it supports JSON native. JSON is perhaps the most important data transmission format in the web, and is also the general structure of the latest NoSQL database. It is very easy to use JSON in JavaScript programs, which means that when you use Node to work, data can be transmitted in a very simple manner without format conversion. You can use only one syntax (in JSON format) to pass between the browser, server, and database.

Round 7: host and deployment

In the seventh round, we will check whether it is easy to deploy new applications to Web servers. in Craig's view, PHP is obviously the winner in this regard.

Bruno:

Bruno again remained silent.

James:

This is a region for Node improvement. Every company that provides Web hosts provides PHP and MySQL. To see the output, you only need to create a file with the extension ". php ". Write some valid code between them, upload them, and access them using a browser. But the same method does not apply to Node. Of course, Node hosts have many options, but they require more settings and command line access, which is unpleasant for beginners. Without a doubt, PHP won the competition in this round.

Round 8: performance

The eighth round focuses on speed. Although this often relies on experience and development teams, Craig notices the advantages of Node in some aspects.

Bruno:

Errors are everywhere. First, this article discusses performance in detail, excluding developer experience and the impact of application types on performance. If the article still doesn't help you understand how ignorant the context is about performance, let me talk about my point of view:

  • PHP is embedding a multi-threaded server. This makes it possible to completely bypass the external server, but it is not recommended for the time being. In addition, there are some super-fast servers (such as Nginx) that make the entire process of starting PHP and distributing requests almost negligible.
  • PHP native asynchronous (non-blocking I/O) support will be introduced in PHP7, and ReactPHP implemented a similar pattern many years ago, so this is meaningless.
  • The lifecycle mode of PHP single-request is the biggest burden. Indeed, if you are simply pursuing speed, but this article can still be easily bypassed, not only through the similar methods mentioned by Memcached and Craig, but through the similar; Ajax method. By the way, the JS application on the server side is also single-request by default. In addition, this single-request life cycle is also an advantage. every request is re-built to avoid many memory problems, clear junk memory, and keep it slim and clean. When was the last time you used a stable and long-running Javascript application without memory leakage, no matter the front-end or back-end?

The performance is now discussed, and it will be a draw in the future (unless you are using Java, Java will definitely lose)

James:

Node is famous for its high-performance and low-latency runtime environment, and it also finds its own way to embed code stacks of some top 500 companies. Because of its non-blocking I/O mechanism and Google Chrome V8 engine technology, Node has now become a synonym for "fast" and "scalable. There are many stories on the Internet, such as how Node can improve the company's performance and provide developers with higher productivity. I'm glad that this round of node wins, but I also understand that some people question this.

Round 9: Programmer complex

In the ninth round, let's take a look at Craig's feelings about PHP and Node. Finally, he thought that Node had won.

Bruno:

You must be mistaken. Craig and the PHP community are hard-confident and active. There are over 20 conferences and wonderful theme discussions each year. This completes PHP7 of HHVM.

In addition, I want to talk about the version that Node developers are using (v0.12.5 is already being written), even after six years of development. This is not mature and dangerous (oh, my God, you are using an unstable technology, are you deliberately letting your company go off, it ignores the old bugs in some operating systems and will lead some important developers to leave the language's ecosystem.

Some negative experiences make me dislike Node, mainly because npm. The future may change, but every time I use Node, I feel fear and disappointment. We all have our own preferences, but it is important to choose the right tool to work objectively. However, it is equally important to allow others to try and make mistakes, because everyone is behind the scenes. So don't listen to Craig, don't listen to Jim or me. Boldly try to see what can be used and find something that makes you feel good to use. In the end, what makes you feel productive is the best, instead of saving some loading time.

James:

Node is very popular, and there are many innovations in the field of Node. Although passion is not objective, it is a pleasure that Node has won this game.

Round 10: Future

The tenth round focuses on the prospects of the two languages. based on the fact that both languages seem to have a strong future at this stage, Craig determined that the result of this round was a draw.

Bruno:

Bruno had to write more articles about PHP and maintain the amazing SitePoint PHP channel.

James:

James cannot wait to return to his beloved JavaScript channel, but he left these points:

The draw is fair for this round. Node is a rising star, but if he wants to shake the throne of PHP, he still needs to make great efforts.

In general, if a hammer is your only tool, then every problem looks like a nail. Node is not perfectly adapted to every solution. of course, it is reasonable to not use Node in many cases. However, Node can do very well. It is up to you to make a wise decision and choose the best tool suitable for your project.

Since both Bruno and James have made their own views, how do you think about this problem?

Bruno Skvorc

Croatia's programmer Bruno has three master's degrees in computer science, English and literature. He is a php columnist on The SitePoint website or a developer at Diffbot.com. he avoids legacy code like plague. he chooses a project to use the latest technology, and he is also a treadmill desk enthusiast and live player. he has a blog: sometimes blogs.

James Hibbard

I am a website developer who currently lives in the sunny northern Germany. I like to use JavaScript and Ruby Programming. you can often see me in SitePoint's javascript Forum. I like running when I don't write code.

The above describes 10 comparison challenges of PHP and Nodejs, including some content, and hope to help those who are interested in PHP tutorials.

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.