What is PHP less than C + + or Java? multithreaded, multi-threaded, multi-threaded ...

Source: Internet
Author: User
Yesterday and a former colleague chatting, all kinds of spit slot PHP, Spit Groove swoole, he thinks PHP everywhere is a hole, PHP is very limited. Php+swoole is not suitable for high concurrent servers, C+swoole is the best solution. C + + has a variety of data structures, C + + can be thread, C + + can share objects. It seems necessary to have a good explanation.

What does HP have less than C + + or Java? multithreaded, multi-threaded, multi-threaded ...

Yes. PHP is much less multithreaded than C + + and Java. PHP has only a multi-process scenario, so the global variables and objects in PHP are not shared, the data structure can not be cross-process operations, socket file descriptors can not be shared, and so on. So PHP has limitations?

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

Data synchronization problems can cause you to crash. Or the performance of the sacrifice of the lock everywhere, or the hell of the difficulty of the lock-free concurrent programming, as far as I know there are few people in the country to master this skill.

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

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

Instead of looking at the multi-process, it is actually much simpler.

In conjunction with interprocess communication, you can basically implement arbitrary data sharing. For example, a process is used to store data structures and objects, and all other processes are posted to this process to

Multiple processes do not require locks

Multi-process can use the data structure of shared memory to realize some multithreading functions. Data sharing is possible with table and atomic provided by Swoole, but at very low cost. Shared memory queues will also be added in the future

The so-called PHP limit Swoole, this is completely nonsense. Using the table, Atomic, Sendmessage/pipemessage, and task provided by Swoole can fully implement asynchronous non-blocking code logic.

is the program written by C + + better performance?

This is totally blind superstition, and the dense computing program C + + does have an advantage. and the concurrent Server Core is IO, not a large-scale intensive operation. C + + has little advantage in terms of the language level. In addition, most of the data structures in C + + have a corresponding implementation in PHP, it is not possible to write a special extension can also solve it.

High concurrent server stand-alone can maintain 10W connection, can process 3-5w pen message send and receive every second. This level of performance can already be applied to the core system of bat.

What is the meaning of fast 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'll tell you what it means to be more efficient. Developing a good set of programs is not an easy task and requires a lot of time and effort from programmers. The significance of development efficiency improvement is not simple I can finish less time, but the rest of the time you can increase unit testing, fix bugs, improve user experience, improve details, provide supporting tools, optimize performance, increase critical log, increase monitoring alarm, increase disaster recovery plan.

  • 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.