The PHP System handles mysql insert operations at the same time by 100 people. Is there any good way to optimize code writing?

Source: Internet
Author: User
Tags mysql insert
In the PHP System, 100 people simultaneously process mysql insert operations. What are the types of optimized code writing tables? myisam and concurrent operations,
Do you need to lock the table as described below?
Or will mysql automatically process 100 requests in queue

Mysql_query ("lock tables 'user' WRITE"); // LOCK the 'user' table $ SQL = "INSERT INTO 'user' ('id', 'username ', 'Sex ') VALUES (NULL, 'test1', '0') "; $ res = mysql_query ($ SQL); if ($ res) {echo' submitted successfully .! ';} Else {echo' failed! ';} Mysql_query ("unlock tables"); // UNLOCK


Reply to discussion (solution)

No need to lock the table during insertion (but you can append the clause that is inserted when Idle)

The table can be locked only when it is modified.
However, it is unreasonable to allow multiple users to modify a record at the same time. Business flow problems

Insert is an atomic operation and does not need to lock the table. It will automatically lock itself.

Here is a scenario description for inserting 100 people at the same time.

No matter how many users you insert at the same time, the database will be written successively, but the user does not feel it

Is the new record added by the landlord's plug-in pure?

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.