PHP is single-threaded. how can we deal with a large amount of http access? At the beginning, I only knew that php could be used as a website and never touched the php thread problem. today I suddenly learned that php is a single thread, but suddenly thought, php websites must be used for access by many people. if there is a large access volume, isn't there a queue problem?
Is this true? Or does apache use the server to implement multithreading when processing php programs?
Reply to discussion (solution)
Nginx + php
Nginx + php
Can you give me more details? Which means apache + php is single-threaded?
Nginx + php
After checking, it seems that apache + php is blocking-type processing, while nginx + php is asynchronous and non-blocking.
Responding to http access is a web server and has nothing to do with php.
Php only appears as a web server script
Responding to http access is a web server and has nothing to do with php.
Php only appears as a web server script
What does it mean that php is a single thread and java Multithreading? For guidance, please explain it in detail, not too deep
PHP can be called with multiple threads on the WEB server!
Php has a process manager, fpm fcgi or something. The php language itself does not have multithreading.
To cope with high concurrency, use nginx or other software for load balancing. At the php layer, gzip can be used for compression and caching.
PHP does not have multiple threads. Therefore, you cannot open another thread in the code to execute other tasks. Unlike java, multiple main line logics are executed at the same time. however, this does not have much to do with large traffic volumes, because the requests are processed by nginx or apache, and then php is called for processing. the calls can be performed simultaneously, will start many processes to access the script, the process is different from the thread. each user will correspond to a php script process on the server. after execution (the page is opened), the process will be destroyed and the memory will be released.
PHP does not have multiple threads. Therefore, you cannot open another thread in the code to execute other tasks. Unlike java, multiple main line logics are executed at the same time. however, this does not have much to do with large traffic volumes, because the requests are processed by nginx or apache, and then php is called for processing. the calls can be performed simultaneously, will start many processes to access the script, the process is different from the thread. each user will correspond to a php script process on the server. after execution (the page is opened), the process will be destroyed and the memory will be released.
In Singleton mode
If ($ instance = null ){
$ Instance = new instance ();
}
Will this cause the server to call multiple php scripts for processing and the two calls will be performed at the same time, resulting in two new instances?
Php will process other processes after processing a process.
All started php interpreters are independent of each other.
The php code that is naturally interpreted by it is also independent of each other.
The so-called Singleton is only applicable to the currently running php code set.
Personally, php is a development language with no threads involved.
PHP does not have multiple threads. Therefore, you cannot open another thread in the code to execute other tasks. Unlike java, multiple main line logics are executed at the same time. however, this does not have much to do with large traffic volumes, because the requests are processed by nginx or apache, and then php is called for processing. the calls can be performed simultaneously, will start many processes to access the script, the process is different from the thread. each user will correspond to a php script process on the server. after execution (the page is opened), the process will be destroyed and the memory will be released.
In Singleton mode
If ($ instance = null ){
$ Instance = new instance ();
}
Will this cause the server to call multiple php scripts for processing and the two calls will be performed at the same time, resulting in two new instances?
Yes. in the Singleton mode, only the script currently running is being executed in PHP. you also pointed out that you must first check whether $ instance is empty, this is only limited to the fact that this running script does not produce multiple objects.