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

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? ------ Solution ---------------- PHP is single-threaded. how should we deal with a large number of http accesses?
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?
------ Solution --------------------
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.
------ Solution --------------------
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.
------ Solution --------------------
Reference:
Quote: reference:

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.