Threading-How does PHP handle multitasking concurrency?

Source: Internet
Author: User
Write a Web program, but the PHP multi-task concurrency mechanism is very puzzled, the internet did not find anything very good information, so very confused, here to consult.

For example, I want to deal with user login such a simple business, I want to use an object-oriented method to write a static class, let its method implementation to the database query an ID of the user's information, then this class can be logged in multiple people at the same time what happens, will it be possible to send a person's information to another person because of concurrency? If so, is there any way to add a thread lock for it to handle such events? Without regard to the lock of the database.

Reply content:

Write a Web program, but the PHP multi-task concurrency mechanism is very puzzled, the internet did not find anything very good information, so very confused, here to consult.

For example, I want to deal with user login such a simple business, I want to use an object-oriented method to write a static class, let its method implementation to the database query an ID of the user's information, then this class can be logged in multiple people at the same time what happens, will it be possible to send a person's information to another person because of concurrency? If so, is there any way to add a thread lock for it to handle such events? Without regard to the lock of the database.

The question you don't have to worry about in PHP is that PHP is a stateless scripting language, meaning that all the variables you create in memory are completely destroyed once the request is complete.

The memory between concurrent requests is completely isolated, and in most cases you can consider multiple concurrency in a single concurrency scenario.

There is no real static class concept in PHP, because everything you create will disappear after the request ends. In fact, if you can get concurrent programs to read a piece of memory, that's a bug.

This is PHP's Web server Thing (Apache), he will protect these things, so you do not have to worry about, I just started to write the program also worried about why two people can log in at the same time? Does a person not overwrite the data of another person? Then I knew that Apache itself could help you get it done.

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