is PHP inferior to C + +?

Source: Internet
Author: User

Yesterday and a former colleague chat, all kinds of spit slot PHP, spit slot swoole, he thought PHP everywhere is a pit, PHP limited. Php+swoole is not suitable for high concurrency server, c+swoole is the best solution. C + + has a variety of data structures, C + + can be a thread, C + + can share objects. It seems necessary to have a good explanation.

What is less PHP than C + + or Java? Multithreading, multiple threads, multithreading ...

Yes. PHP is a lot less multi-threaded than C + + and Java. PHP has only a multi process scheme, so the global variables and objects in PHP are not shared, the data structure cannot be manipulated across processes, the socket file descriptor cannot be shared, and so on. So PHP has limitations?

Multithreading seems to be a lot more powerful than many processes, in fact I can responsibly tell you that multithreading brings more holes .

    • Data synchronization issues can make you crash. Either at the expense of the performance of the lock everywhere, or in the hell of the difficulty of the non-lock concurrent programming, as far as I know the current domestic ability to master this skill is rare.

    • Don't think the lock is all right, you will have a big somersault on the deadlock problem. When the logic of your program is complicated, the lock becomes more and more difficult to control, once the deadlock your program is basically finished.

    • A thread hangs, and all the threads will exit.

Instead of looking at multiple processes, it is actually much simpler.

    • With interprocess communication, you can basically achieve any data sharing. For example, a process dedicated to the storage of data structures and objects, the other processes of data operations are all posted to this process to

    • Multiple processes do not require locks

    • Multi-process can use the data structure of shared memory to implement some multithreading functions. such as Swoole provides table, atomic can realize data sharing, but the cost is very low. will also join the shared memory queue in the future

The so-called PHP limit Swoole, this is completely nonsense. Reasonable use of swoole provided table, Atomic, Sendmessage/pipemessage, task can fully implement asynchronous non-blocking code logic.

C + + Write the program performance better?

This is totally blind superstition, the intensive computing program C + + does have an advantage. And the core of the concurrency server is IO, not a large-scale intensive operation. C + + has no advantage from a linguistic perspective. In addition, C + + Most of the data structure in PHP has a corresponding implementation, it is not enough to write a special extension can also be resolved.

A high concurrency server can maintain a 10W connection, and can handle 3-5w pen messages per second. This performance level can already be applied to bat's core system.

What is the meaning of rapid development efficiency?

The colleague also said that PHP development server, although faster than C + +, but the pursuit of the ultimate performance is to use C + +. I'm going to tell you what it means to be more efficient. Developing a good program is not an easy task and requires a lot of time and effort from the programmer. The significance of development efficiency improvement is not simple I can be less time to complete, but the rest of the time you can increase unit testing, fix bugs, improve user experience, improve the details, provide supporting tools, optimize performance, add key logs, increase monitoring alarm, increase disaster recovery program.

(the author is the founder of Swoole, in the original title: "About C + +, PHP and Swoole")

Original: http://rango.swoole.com/archives/473 Author: @ Hantian-rango



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.