PHP System 100 people at the same time to handle the MySQL insert operation, what good code to optimize the coding

Source: Internet
Author: User
Tags mysql insert
PHP System 100 people at the same time to handle the MySQL insert operation, what good code to optimize the coding
The type of table is MyISAM, concurrent operation,
Do you need to lock the table as follows?
Or is MySQL automatically queued to process 100 requests in turn

mysql_query ("Lock TABLES ' user ' WRITE");//Lock ' user ' table
$sql = "INSERT into ' user ' (' id ', ' username ', ' sex ') VALUES (NULL, ' test1 ', ' 0 ')";
$res = mysql_query ($sql);
if ($res) {
Echo ' submitted successfully.! ';
}else{
echo ' Failure! ';
}
mysql_query ("UNLOCK TABLES");//Unlocked

------to solve the idea----------------------
No lock table is required when inserting (but you can append clauses that are inserted when idle)

You may need to lock the table only if you modify it.
But allowing multiple people to modify a record at the same time is inherently counterintuitive. Problems with business processes
------to solve the idea----------------------
Insert is an atomic operation and no lock table is required. itself will be locked automatically.
------to solve the idea----------------------
Give me a 100-man scene description for simultaneous insertion
------to solve the idea----------------------
No matter how many people you plug in at the same time, the database will be written in succession, but users do not feel
  • 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.