Php synchronization proposal

Source: Internet
Author: User
Php synchronization scheme php synchronization execution is quite troublesome. according to the mysql documentation, this can be done. ========================================================== ==================================== GET_LOCK (str, timeout) try to get a php lock synchronization scheme using the name specified by the string str
Php synchronization execution is quite troublesome. according to the mysql documentation, you can.


========================================================== ======================================
GET_LOCK (str, timeout)
Try to get a lock by using the given name of the string str. the timeout value is timeout seconds. If the lock is obtained successfully, 1 is returned. if the operation times out, 0 is returned (for example, because the name of another client has been blocked in advance ), if an error occurs, NULL is returned (for example, the thread mysqladmin kill is disconnected ). Assume that you have a lock obtained by using GET_LOCK (). when you execute RELEASE_LOCK () or your connection is disconnected (normal or abnormal), the lock is released.

This function can be used to execute application locks or simulate record locks. The name is locked within the server range. If a name has been blocked by a client, GET_LOCK () will block any requests from another client requesting to block the same name. This allows the client that has reached an agreement on a blocking name to use this name for cooperation to execute the recommended lock. However, you need to know that it also allows a client block name that is not in a combination of clients, whether in service or intentionally, to prevent any client in cooperation from blocking this name. One way to reduce this is to use database-specific or application-specific blocking names. For example, use the blocking name in the form of db_name.str or app_name.str.


========================================================== ======================================

If a file is not intended to be concurrently accessed by the user, it can only be accessed in sequence,

If the file a. php is not expected to be accessed by two requests at the same time, you can:

$ Db = getdb (); // Obtain the database connection.

$ Db-> query ('Do get_locak ');

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.