Two old friends finally separated by fighting. this is a classic Hollywood plot. Usually, friction begins when one is not interested in another person's speech. In the programming language movie, the introduction of Node. js makes friends easy...
Two old friends finally separated by fighting. this is a classic Hollywood plot. Usually, friction begins when one person is not interested in another person's speech. In the programming language movie, the introduction of Node. js makes friends easy to become resentful opponents: PHP and JavaScript. The two partners once ruled the Internet together, but now they are separated from each other.
It's easy to go through a cooperative relationship. JavaScript handles the details on the browser, while PHP manages all server tasks between Port 80 and MySQL. This is a happy alliance that supports many key parts of the Internet. In WordPress, Drupal, and Facebook, PHP is involved almost every minute on the Internet.
Then some smart developers discovered that JavaScript can be used on the server. Suddenly, there is no need to use PHP to build a server stack. A language can be used to build Node. js and is also required by the client runtime framework. "JavaScript everywhere" has become the mantra of some people.
Since then, both platforms have been constantly expanding and improving. Node. js developers can now choose an excellent framework set that is constantly expanding: Express, Angular, Meteor, and so on. The list is very long. The biggest problem is choosing the best and most suitable one.
PHP also accelerates the speed. zippy instant compiler provides faster answers than before. Currently, both PHP 7.0 and HHVM provide the same instant optimization engine V8 for Chrome and Node. js. In addition, HHVM also has an Hack that fully supports complex programming features such as lambda, generics, and collections.
Some people praise Node. js and JavaScript, and others are satisfied with the PHP code Foundation and stability. Will JavaScript still rule the world with its old friends?
PHP features: Mixed Code
If you want to add a branch, you can use an if-then statement, which looks pretty. Or you may want to mix text or data in the database. With PHP, open the PHP tag and write the code in a few seconds. No template is required, because everything is a template! You don't need additional files or well-designed architectures, just programming at your fingertips.
Node features: code separation
Mixed code may not be a good thing in the end. Although this is interesting, your code will soon become logically messy. A real programmer adds a structure and separates the base layer from the logic layer. This makes the code clearer and easier to understand and maintain for new programmers. The framework running on Node. js is built by the programmer. the programmer knows the model, and it is best to separate the view from the controller.
PHP features: deep code library
The network is full of PHP code. The most popular platform for building websites (WordPress, Drupal, Joomla) is written in PHP. Not only is the platform open-source, but also most plug-ins. PHP code is everywhere.
Node Features: Updated code means more modern features
Of course, there are thousands of great open-source PHP files, but who wants to spend hours, days, or weeks researching unupdated code for years? The Node. js plug-in is not only updated, but also based on the latest architecture method. They are built by programmers who know that modern network applications should push most of their intelligence to clients.
PHP features: Simple (sorting)
PHP does not have many things: some variables and basic functions are used to compile strings and numbers. In addition to moving data from Port 80 to the database and back, PHP is not complicated.
Node features: complex closures
JavaScript may have many small features, but in most cases it is a modern language that runs modern syntax and some useful functions such as closures. You can easily reconfigure and expand it to make it possible for powerful libraries such as jQuery. you can pass functions similar to objects.
PHP features: new code is being created
If you are a programmer and want to do more than just interact with the database, but format the results, now you can use PHP to do a lot of things. Facebook's HHVM has added support for Hack. Hack is a complete language, full of modern features such as type annotations, generics, and lambda expressions. This will limit the code to run only on HHVM.
Node features: Dozens of language options
If PHP users are willing to access Hack, they should consider migrating to Node. js world, because many major languages can be cross-compiled to run in JavaScript, such as Java, C # or Lisp and Scala, OCaml and Haskell.
PHP features: no client applications required
It is good to use the same language in the browser and server, but what if you do not need to use any language in the browser? What if I send data in HTML format? HTML is used more frequently than anything else, and PHP has been optimized to create it. so, why use JavaScript on the browser?
Node features: the foundation for efficient delivery
If you are willing to take the time to create a beautiful browser network application, Node. js can provide data through Web services after optimization. If your applications are complex and rich in data, this is a good foundation for efficient delivery.
PHP features: SQL
PHP is built to coexist with MySQL and many of its variants (such as MariaDB. If MySQL is incorrect, there are other SQL databases from Oracle and Microsoft. The code can make some changes to the query. Some stable and well-developed code will be connected to the SQL database, which means it can be easily integrated into the PHP project.
Node. js features: JSON
It does not mean that the JSON library cannot be obtained for the PHP stack, but JSON is simpler and more flexible when JavaScript is used. It is a syntax from a browser to a Web server to a database.
PHP features: encoding speed
For most developers, it feels faster to write PHP for Web applications: no compiler, no deployment, no JAR files or pre-processors, just your favorite editor and PHP files in some directories. PHP is the best tool when a project requires rapid development.
Node. js features: Original speed
It is difficult to write JavaScript code when you include braces and parentheses. Its core lies in precision and accuracy.
PHP features: internal competition
The HHVM team and Zend team are working hard to provide quick code for everyone. When there is an independent benchmark, everyone pushes the code to the limit, which means better performance.
Node. js features: integration and unity
Do you really want two different code libraries? Competition is conducive to development, but fragmentation will soon emerge. If you have to spend a few weeks or months to rewrite the code, competition will not be of any benefit. Although Node. javaScript split several years ago, along with io. the launch of js, Node. the Universe of js has been re-unified, and it has provided PHP developers with a language unity that has never been used for a long time.
The above are the details shared by PHP and Node. js-an epic developer. For more information, see other related articles in the first PHP community!