Say I have a website, with 2 users on the site.
Both load a php page which inserts 1000 big rows into mysql, it loads them using a for loop.
Right now, the inserts are crossing, for example, 15 inserts from user 1, then 3 from user 2, then 5 from user 1…
How can I make it so if user 1 loads the php file first, then user 2 must wait until user 1 has finished inserting all 1000 of his rows before user 2 can begin?
Use MySQL insert delayed, here is the docs: http://dev.mysql.com/doc/refman/5.5/en/insert-delayed.html
It will queue your insert queries, just when a one has finish the other will begun. But if you want to join all the queries from an user before to send the second query, this will be a lite more complicated, maybe a temporary table in the memory can help you hold the user sessions table before actually make the insert. But I think that insert delayed will solve your problem.