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.