Bir web uygulamasında eşzamanlı işlemleri önlemek

0 Cevap php

We have a web application (it is a game) with lots of various forms and elements which act as buttons and trigger some actions on server. The problem is that users can sometimes confuse our application if he clicks on buttons too fast or opens the website in two tabs and then issues some actions simultaneously. We have some basic protection - MySQL transactions, some double-click preventing Javascripts, but anyway sometimes something just skips out. Of course, the best way would be to redesign all the SQL transactions and supporting functions in the way that does not allow to confuse the system. One example of such confusion is issuing two updates simultaneously - one web request changes something in the db, but the second request operates still with the old data and so SQL update returns "number of affected rows was zero" because the first transaction has already changed data in the db. The obvious solution is to read data once again right before UPDATE to see if it still needs updating, but that means putting many more double SELECT queries everywhere, not a good solution - why to read the same data from db twice? Also we have considered using some hidden token to compare on the server on each updating request and deny operations which have the same token id, but this also means touching really many places of code and possibly introducing new bugs into the system which works just fine except this one problem.

Eylem akışının mantığı şu olacaktır: kullanıcının aynı anda iki dilekçelerini ise, ikinci isteği ilk tamamlanıncaya kadar beklemeniz gerekir. Ama biz de (kullanıcı sayfayı yeniler zaman Mesajları çift yayınlamaktan kaçınmak sonra örneğin) pek çok yönlendirmeleri bizim uygulama olduğunu düşünmek gerekir, bu nedenle çözüm kullanıcı için kilitlenmeleri oluşturmanız gerekir.

So the question is: what would be the most easy possible global fix which could just somehow make all the user operations sequential? Is there any good universal solution?

Biz MySQL ve PHP kullanıyor.

0 Cevap