PHP is single-threaded, how to deal with a large number of HTTP access

Source: Internet
Author: User
PHP is single-threaded, how to handle a lot of HTTP access?
Just started to know that PHP can do Web site, never contact PHP thread problem, today suddenly learned that PHP is single-threaded, but suddenly think, PHP do the site is definitely for many people access, if the traffic is large, it is not a queue problem?
Is that true? or Apache in the processing of PHP programs will use the server to implement multi-threading it?
------Solution--------------------
PHP does not have many threads, so it is not possible to open another thread in the code to perform other tasks, like Java, there are multiple mainline logic executing at the same time. But this does not have much to do with large traffic, because the request comes in Nginx or Apache processing, and then calls PHP processing, The invocation can be done concurrently, opening many processes to access the script, and the process is different from the thread. Each user will correspond to a PHP script process for the server, after execution (the page is opened), the process is destroyed and the memory is freed.
------Solution--------------------
All PHP interpreters that are started are independent of each other.
The PHP code that is naturally interpreted is also independent of each other.

The so-called Singleton, just for the current set of PHP code to run
------Solution--------------------
References:
Quote: References:

PHP does not have many threads, so it is not possible to open another thread in the code to perform other tasks, like Java, there are multiple mainline logic executing at the same time. But this does not have much to do with large traffic, because the request comes in Nginx or Apache processing, and then calls PHP processing, The invocation can be done concurrently, opening many processes to access the script, and the process is different from the thread. Each user will correspond to a PHP script process for the server, after execution (the page is opened), the process is destroyed and the memory is freed.

In the singleton mode
if ($instance = = null) {
$instance = new instance ();
}
Will this block be processed because the server calls multiple PHP scripts, and two calls are made at the same time, resulting in a new two instance?


Yes, the singleton mode in PHP will only be in the current run of the script, you also pointed out, is to detect whether $instance is empty, this is only limited to the run of the script will not new out of 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.