国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php - 數(shù)據(jù)庫與邏輯應(yīng)用分離的情況下怎么保證信息同步,或者叫安全
迷茫
迷茫 2017-04-17 16:48:34
0
6
1028

我不太明白這個(gè)詞怎么表達(dá)

是這樣的,現(xiàn)在有一臺服務(wù)器運(yùn)行數(shù)據(jù)庫(server),另外一臺運(yùn)行php程序(client),瀏覽器(Browser)訪問client,然后client邏輯判斷后通過http協(xié)議對server中的數(shù)據(jù)庫進(jìn)行CURD操作

有個(gè)問題就是,如果Browser的用戶操作過快,而serverclient之間http請求太慢的話,就會(huì)導(dǎo)致client上獲取的數(shù)據(jù)更新不及時(shí),導(dǎo)致一些錯(cuò)誤。。

栗子:一個(gè)用戶只能買一個(gè)商品,用戶點(diǎn)擊之后,client先讀取server的數(shù)據(jù),判斷是否已經(jīng)購買,沒有購買的話進(jìn)行寫入操作,然后購買完成,但是如果用戶連著點(diǎn)擊兩次購買,兩次操作一次進(jìn)入client,然后由于clientserver之間網(wǎng)速或者其他一些問題,寫入操作沒有及時(shí)完成,造成兩次購買操作的判斷為此用戶未購買,于是會(huì)有兩次寫入server數(shù)據(jù)庫的操作,就會(huì)造成錯(cuò)誤。。

這個(gè)問題屬于什么?應(yīng)該怎么解決?

迷茫
迷茫

業(yè)精于勤,荒于嬉;行成于思,毀于隨。

reply all(6)
劉奇

Use an in-memory database or NOSQL database to interact with the client, and then the in-memory database is "synchronized" with a relational database such as MYSQL.

If certain operations on the client require database queries to determine, errors can easily occur if there is high concurrency. I have experienced it before. For example, when user registration is used to determine whether there is a duplicate name, in theory, the database is first queried to see if the user name exists and then inserted. However, in actual operations, this logic was broken, and a user with the same name was discovered.

So put the core data in a relational database, and use an in-memory database if speed is required. Use caching appropriately to reduce duplicate queries.

左手右手慢動(dòng)作

The general solution is for the server to provide the token first. Only with the token can the operation be successful. If it is used up, it will be marked as expired. This can not only ensure that operations are not repeated, but also can perform functions such as current limiting.

And your question is a bit wrong. If it is the security of communication between the database and the business server, you can use the SSL protocol.

Another approach is to use consistent hashing to calculate the business ID without incrementing the ID. This can ensure that many operations are idempotent. If you are interested, you can give it a try.

Peter_Zhu

Thank you for the invitation, your Lizi client can make the decision

左手右手慢動(dòng)作

Distributing tokens and the like is of course a very good solution. However, in practical application, I think the following solution is more concise and efficient:

  1. After processing in the front-end js, after clicking the [Purchase] button, a full-screen mask will pop up to prevent the user from clicking the second time. When the background is successful, the mask will be removed. In addition, you can also use flag bits, or use the classic debounce/throttle algorithm.

  2. The background also determines during the purchase process that when repeated purchases are made within a short period of time (such as within 10 seconds), an error of "Please do not repeat the operation" will be returned directly. On the database side, you can consider using transactions and increasing the isolation level of the transaction, or using locks.

Generally, after processing it in the front-end js, many problems can be avoided. Unless there is a malicious user.

伊謝爾倫

To add concurrent locks, you can use redis, memcached, etc., and release the lock after a request is completed

// 操作的原子性,如該key在有效時(shí)間30秒被設(shè)置過返回0,一般請求超時(shí)為30秒
$redis->set($lock_key, 1, array("NX", "EX"=>'30'));
黃舟

From the above, you can see that you have two servers, one running php and the other db. But why do you need to use the http protocol for communication between your two servers? Instead of using the default connection protocol of mysql (assuming you are using mysql)? In other words, you should directly connect to your server's database in php, and then operate the DB.

For the continuous insertion problem mentioned in your example, it can be solved through table structure design, and the unique index UNIQUE can be added to the field. There are also some other methods, and I personally recommend the unique index method

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template