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