PHP is single-threaded. how can we deal with a large amount of http access?

Source: Internet
Author: User
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.

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.