About Node.js: 5 points that all PHP developers should know

Source: Internet
Author: User
Tags pack pear php and thread what php drupal

I recently started to deal with Node.js. Before doing PHP development, especially Drupal, I found it easy to transfer to Node.js, and the process was very enjoyable! But I also need to learn to think from a number of different angles. Here's a list of 5 node.js features I think PHP engineers should know.

1. The node.js is built on the chrome JavaScript engine

Google's browser Chrome, has a very fast JavaScript engine, called V8. This JS engine can be independently released. Node.js is built on the V8. That's why Node.js is running so fast. For developers, there are several benefits:

You don't need to learn a new language again, it's JS. I often look at Chrome and Mozilla's JS files, and they're completely generic.

Benefiting from the V8 JIT (Just in time) compilation feature, Node.js applications can run at speeds comparable to local code. Comparison tests indicate that Node.js is much faster than PHP and Ruby.

With the progress of V8, Node.js will benefit at the same time.

2. Node.js is more than just a Web server or platform

Unlike PHP, Node.js is not web-centric. Node.js is the common purpose of JS runtime, with many powerful libraries. One of the libraries provides a HTTP/HTTPS implementation.

You can do a lot of things with node.js. You can easily use it to create a command-line program or other TCP/IP services.

3. Node.js is object-oriented (albeit strangely)

I like jquery. But it makes me lazy, writing a lot of simple, fast but difficult to see the structure of the script. It's not a bad thing, because it's enough to handle simple web behavior. But Node.js is not just for working with browsers, it can be used to build applications, which means you have to think about the program architecture. When you write code with Node.js, you will delve into the JS object model. I used to hate the object model of JS, often make me crazy. But Node.js and NPM (Node Package Manager) make good use of JS prototype system, help me clear a lot of class/interface use of obstacles, let me fall in love with object-oriented JS programming.

4. Event-based I/O

This is the most controversial point of node.js. Node itself runs in one thread. Yes, only one! You can compare the traditional apache/php with a bunch of examples. But node runs very fast and efficiently.

How did this happen? Share execution time, placing intensive IP processing on other threads. The pros and cons of this point I can write a long text to discuss, but here I would like to say something practical: When you write code with Node.js, you need to consider whether your task is slow, or I/o-intensive. Use asynchronous methods to handle callbacks or use event handlers to handle slow work.

Most of all, you want to ensure that the code does not allow a request to occupy the node main thread too long event, and does not give other requests processing opportunities.

5. Must use Package management!

Frankly speaking, do you like pear? Did you convert most of your code into pear or pecl? Not many PHP programmers do this, and even a lot of people don't know that pear exists. In the Node.js world, you have to pack your code:

Node.js's design is one of the most streamlined frameworks. 90% of what is in the core of PHP does not appear in the Node.js core. For example, database drivers, mail-sending libraries, HTML support, and so on, are not in the core library.

The core of Node.js is a modular framework. You'll find it very handy!

NPM (Node Package Manager) is a necessary tool for you. With it, you can download Node.js's various code packs, drivers, parsers, editors, servers, and so on.

It is easy to create and publish your code package. I posted my first code pack shortly after working with node.

If you are a Drupal developer, you will feel that node's package management system is a bit like Drupal's module, the difference is that you are now facing the developers, not the site.

Conclusion: Ask your doctor if Node.js is right for you.

I mentioned a lot of what PHP developers should know about, Node.js features. There are thousands of articles on Node.js on the internet, mostly positive. Node is an interesting product and it has an elegant architecture. But node is not a panacea. I don't think node can replace PHP immediately. I just think that PHP developers should learn node.js. It's very simple and useful.

Related Article

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.