My web app allows users to upload a bunch of photos simultaneously to the server, and then stores them in a database. When the first photo finishes uploading, it should create a default album based on today's date, and add it to that. But what if photo1 completes, looks for the album, and can't find it so it decides to create it, but before it can, photo2 completes and also can't find it, so then they both try to create the same album, causing one to fail? This would probably be very highly unlikely, but could happen I reckon. Or do most web servers process only one PHP script at a time?
Would this be a valid and good solution?: Instead of photo1 checking if the album exists first, it just tries to create it. If it throws back an error 1062 (duplicate entry), THEN it selects it. Then it shouldn't matter which finishes first if you think about it... I just don't know if catching errors will come as a big performance hit. If I'm uploading 200 photos, then 199 of them will fail the insert query, and then try select. If the other solution works correctly, 199 will succeed and one will miss.
Thoughts?