node. js Subversion: PHP's Swoole extension

Source: Internet
Author: User

In the last 2 years, node. JS is a hot, asynchronous and co-development topic. In the pursuit of new technology, but also should reflect on the existence of the trap. node. JS is really a fun and fun personality language and technology, dynamic, full async callback, closures and so on. It's worth all the programmers to try.

But this article will introduce a different easy to be despised by everyone programming language: PHP. PHP has long been used as a front-end scripting language for Web development. PHP is extremely simple, you can only master it in a week, developed a feature-rich website in January. The development of PHP has been completely no longer a simple language, PHP features Paul Vientiane, commonly used operating system functions, such as process management, signaling, network communications, multi-threading, Ptrace, INotify, encryption and decryption, compression has a corresponding extension implementation, and PHP can be very good with C/s + + calls each other. PHP provides ZENDAPI, which makes it easy to use C to augment PHP functionality. Language features PHP5.4 provides Namespace,phar packaging, composer Dependency management, Trait, complete object-oriented programming syntax, powerful magic methods and constants, string and function class object direct conversion, closures and anonymous functions, and other rich language features. The back-end development is as powerful as java,c#, but more efficient to develop.

PHP vs. js Advantage 1, PHP development efficiency is higher

PHP is simpler and more straightforward than node. JS, which is a bit like C. Using PHP to develop a feature that is almost the most efficient of all languages, not one.

2, PHP programmer more

Because PHP is easier to get started, the number of programmers is far more than other languages. Other language programmers also have a large part of PHP.

3, PHP open source projects more

PHP has a large number of open source projects, with a variety of third-party libraries

One of the biggest features of node. JS is the built-in asynchronous, high-performance socket server/client implementation, which provides a built-in Web server. PHP also has a similar artifact, that is, the swoole extension. With the swoole extension, a high-performance, secure and stable server program can be developed entirely. No less than node. js, and in some ways more powerful than node. js.

Swoole is written in C language and runs in PHP extensions. The Swoole network IO portion is based on the Epoll/kqueue event loop, which is fully asynchronous and non-blocking. The Business logic section is run using a multi-process synchronous blocking approach. This ensures that the server can handle high concurrency and a large number of TCP connections. Also ensure that the business code can still be easily written.

Swoole vs. js Advantage 1, Swoole is native support multi-process/multi-threaded

Developers only need to modify a parameter, configure the number of processes to start. and node. JS's network library itself does not provide multi-process/multithreaded implementations. Developers need to create their own processes. Or simply use a single thread. This does not make full use of multicore.

2. Swoole using message Delivery + Multi worker process instead of multithreading + shared memory + lock

, the performance of shared memory is very good, but there are security issues that need to be locked when reading and writing. The lock's grain through the convention causes only one thread to run. The lock is too complex and there is a deadlock problem. So developers need to be very careful.

of traditional

3. Swoole code writing is synchronous, not nested asynchronous callbacks

If the code for node. JS is too complex, it will nest multiple callbacks, render the code unreadable, and the program flow becomes messy. Swoole uses the traditional Linux semi-synchronous half-asynchronous multi-worker implementation mode. The business code is written in a synchronous fashion and is simpler.

The Swoole also has a built-in socket client implementation, but is implemented in synchronous + parallel mode. PHP itself also provides the function of the socket, but some functions have some bugs, and more complex. Swoole built-In client classes are more secure and simplified.

4. Swoole built-in additional features that are not available with node. js

such as CPU affinity settings, daemon process, mixed udp/tcp multi-port monitoring, multi-timer and so on.

Are there any successful cases?

A large domestic company well-known SNS website, the global ranking 200. The internal has been developed using this method. There are more than 600 php-language-developed SOA servers developed by WEBSERVER,200. More than 300 asynchronous transaction servers.

node. js Subversion: PHP's Swoole extension

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.