JavaScript-If there are multiple Ajax access backgrounds in a page, is the background single-threaded at the moment? or multithreading?

Source: Internet
Author: User
Tags php multithreading
If the backend is using the thinkphp framework, page multiple AJAX access back-end server, the background server is asynchronous single-threaded or multi-threaded operation? A friend I know can talk to me.

Reply content:

If the backend is using the thinkphp framework, page multiple AJAX access back-end server, the background server is asynchronous single-threaded or multi-threaded operation? A friend I know can talk to me.

The default is multi-process non-multi-threading, a process that processes a request. PHP multithreading needs to install the extension implementation, but the same process receives an HTTP request, unless you implement a Web server in PHP, and then distribute the request with multithreading, you can implement a thread a request.
Apache default is Prefork mode, PHP as a module modules, a request to create a new process response, the maximum number of processes depends on the Apache configuration. Nginx is through fast-cgi and PHP-FPM communication, is also a request a process, the maximum number of processes depends on the PHP-FPM configuration.
If a request back-end processing time is blocked, multiple identical requests are filled with the number of processes, and all subsequent requests will appear waiting for the available sockets

This depends on your server side, is single-threaded or multi-threaded, or even multi-process.

And that's what I understand. 单线程 多线程

For example, you use a form 上传文件 , this is just a request, you only launched the upload file this request, the server in the receipt of your upload file request, found that your file is really big Ah, he wants to be a person to carry the words estimated 10 o'clock night can not work, and then automatically ( fork ) some helper, Equivalent to the creation of some new threads to help him complete the file upload, multi-person collaboration is sure to be fast, so you can complete your large file upload in minutes, this is multithreading,

A single thread is a man's bitter handling till dawn,

So, whether the server is single-threaded or multithreaded, not depending on client how many requests you initiated, the customer service side to initiate 10,000 requests (whether synchronous or asynchronous), which is called 并发 , and multithreading nothing to do,

A single thread is not able to implement concurrent requests.

Can brain fill such a scene: The user's downstream speed is 1k, and then request a 1M picture, if the server single-threaded, the next request to wait 17 minutes to start responding, it is obviously impossible to let you play this way.

So the WEB server must be multithreaded.

The number of threads, is generally more than 4 single-digit, but this is the browser limit, the number of requests per page is limited, more will be thrown into the queue, and so on, this is why sometimes a page refers to the Google CDN file, but even the page pictures are not loaded out of the reason.

What I am puzzled about is this: I am puzzled that apache+php is blocked and nginx+php is asynchronous. So if it's an Apache server, is the PHP side blocking the response to Ajax requests?

PHP is a single-process single-threaded model. The AJAX request you are talking about is also equivalent to an HTTP request, so there are no multi-line threads. JS Ajax is asynchronous request implementation!!!

Client side and server side processing request mode (single thread, multithreading) depends on the scenario, most scenarios, server side parallel non-blocking

  • 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.