Yes. PHP has less multithreading than CC ++ and Java. PHP only has a multi-process solution. Therefore, the global variables and objects in PHP are not shared, and the data structure cannot be used to perform cross-process operations. yesterday, I chatted with a former colleague and spoke with various PHP programs, swoole thinks PHP is everywhere, and PHP is very limited. PHP + Swoole is not suitable for high-concurrency servers. C + Swoole is the best solution. C ++ has various data structures. C ++ can open threads and C ++ can share objects. It seems necessary to explain it.
What is less HP than C/C ++ or Java? Multithreading, multithreading, multithreading ......
Yes. PHP has less multithreading than C/C ++ and Java. PHP only supports multi-process solutions. Therefore, global variables and objects in PHP are not shared, data structures cannot be operated across processes, and Socket file descriptors cannot be shared. So PHP has limitations?
Multithreading seems much more powerful than multi-process. In fact, I can tell you responsibly that multithreading brings more pitfalls.
Data synchronization will crash you. Either sacrifice performance and lock everywhere, or use the hard-to-lock concurrent programming of hell. as far as I know, there are very few people in China who can master this skill.
Don't think that locking is all right, and you will have a big heel on the deadlock issue. When your program logic is complex, the lock becomes more and more difficult to control. once the deadlock occurs, your program is basically finished.
If a thread fails, all threads will exit.
Instead, it is much simpler to look at multiple processes.
In combination with inter-process communication, you can achieve any data sharing. For example, a process stores data structures and objects, and all data operations of other processes are shipped to this process.
Multi-process locks are not required
Multi-process functions can be implemented using the data structure of shared memory. For example, Table and Atomic provided by Swoole can achieve data sharing, but the cost is very low. Will join the shared memory queue in the future
The so-called PHP limits Swoole, which is completely nonsense. Reasonable use of the Table, Atomic, SendMessage/PipeMessage, and Task provided by Swoole can fully implement asynchronous non-blocking code logic.
Is the program written in C ++ better in performance?
This is completely a blind superstition, and intensive computing programs C ++ are indeed advantageous. The core of the concurrent server is I/O, rather than large-scale intensive computing. C ++ has no advantages in terms of language. In addition, most of the data structures in C ++ are implemented in PHP. you can solve this problem by writing a special extension.
A high-concurrency server can maintain 10 million connections and process 3-5 million messages per second. This performance level can already be applied to the core BAT system.
What is the significance of fast development efficiency?
This colleague also said that although PHP development Server is faster than C ++, it still needs C ++ to pursue the ultimate performance. I want to tell you what efficiency means. Developing a good set of programs is not an easy task. it requires a lot of time and effort from programmers. The improvement in development efficiency is not simple. I can finish it in less time, instead, you can add unit tests, fix bugs, improve user experience, improve details, provide supporting tools, optimize performance, add key logs, add monitoring alarms, and add disaster tolerance solutions for the rest of the time.