Thread-how does PHP handle multi-task concurrency?

Source: Internet
Author: User
I wrote a Web program, but I am confused about the mechanism of PHP multi-task concurrency. I have not found any good information on the Internet, so I am very confused. I would like to ask here. For example, if I want to process a simple business such as user login, I want to use an object-oriented method to write a static class so that its method is implemented... I wrote a Web program, but I am confused about the mechanism of PHP multi-task concurrency. I have not found any good information on the Internet, so I am very confused. I would like to ask here.

For example, if I want to process a simple business such as user login, I want to use an object-oriented method to write a static class, let its method be used to query the user information of a specific ID in the database. What happens to this class when multiple users log on at the same time, will it be possible to transmit one person's information to another person due to concurrency? If so, is there any way to add something like a thread lock for it to handle such events? Without considering the database lock.

Reply content:

I wrote a Web program, but I am confused about the mechanism of PHP multi-task concurrency. I have not found any good information on the Internet, so I am very confused. I would like to ask here.

For example, if I want to process a simple business such as user login, I want to use an object-oriented method to write a static class, let its method be used to query the user information of a specific ID in the database. What happens to this class when multiple users log on at the same time, will it be possible to transmit one person's information to another person due to concurrency? If so, is there any way to add something like a thread lock for it to handle such events? Without considering the database lock.

You don't have to worry about this problem in php, because php is a stateless scripting language, that is to say, all the variables you create in the memory will be completely destroyed after a request is completed.

The memory between concurrent requests is completely isolated. In most cases, you can use single concurrency to consider the issue of multi-concurrency.

Php does not have the real static class concept, because everything you create will disappear after the request is complete. In fact, if you can allow concurrent programs to read a piece of memory, it is a bug.

This is the web server (apache) Where php is located. It will protect these things, so you don't have to worry about it. When I first started writing a program, I also worried about why two people can log in at the same time? Does a person not cover the data of another person? Later I realized that apache itself could help you solve the problem.

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.