Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial :多用户同时访问时的问题?

:多用户同时访问时的问题?

Jun 23, 2016 pm 01:48 PM
Multi-user access

请各位大牛不吝指教,先谢过去了!
情况描述如下:

系统结构:1. 界面模块(php) -->2. 中间接口(php) --> 3. 数据库(mysql)
1. 界面模块:显示操作界面及操作结果;
2. 中间接口:负责界面模块和数据库之间的数据交换,及其他功能(跟求助问题无关,不加以描述);

大致流程:从界面模块发送http请求,该请求发送给接口模块,接口模块访问数据库获得数据,返回给界面模块;

问题来了:
界面模块有大量访问用户,这些用户可能同时发送同样的请求给接口,比如:同时编辑某一数据。

问:如何才能避免这种问题?

不知道有没描述清楚,请各大牛赐教,谢谢!


回复讨论(解决方案)

加锁

若业务上允许“同时编辑某一数据”,则以最后提交的为准
否则在收到请求时返回 xxx正在编辑

谢谢斑竹的指教!能详细点吗?合作方要求只能在界面模块进行限制同时编辑某一数据。

在用户A编辑某条新闻读取成功时,将这条数据的状态字段设为1,记录读取的时间戳
此时再有人想编辑,状态1就拒绝
用户A的页面ajax轮询,每隔几十秒告诉服务器还在编辑并刷新时间
当A编辑提交,或用户B想编辑状态为1,但是最后一次ajax提交的时间和当前差太多,就设置状态为0

在用户A编辑某条新闻读取成功时,将这条数据的状态字段设为1,记录读取的时间戳
此时再有人想编辑,状态1就拒绝
用户A的页面ajax轮询,每隔几十秒告诉服务器还在编辑并刷新时间
当A编辑提交,或用户B想编辑状态为1,但是最后一次ajax提交的时间和当前差太多,就设置状态为0



谢谢您的回复,我有些疑惑在界面模块可以这样做吗?我曾讨教过一位做了多年php的朋友,他告诉我这没法整。
之前我也想过设置标识,因为无法操作数据库,所以放弃了。

编辑的时候不需要权限么?A发的B也可以编辑么?

编辑的时候不需要权限么?A发的B也可以编辑么?



谢谢您的到来!
编辑的时候需要权限,但可以在线多个有权限的用户进行编辑某一条数据。

不允许同时编辑同一条记录,是业务层面的需求
业务需求的实现,应在 中间接口 中完成。如有特殊需求,也可在 界面模块 完成
你的这个需求还是应在 中间接口 中完成的

不允许同时编辑同一条记录,是业务层面的需求
业务需求的实现,应在 中间接口 中完成。如有特殊需求,也可在 界面模块 完成
你的这个需求还是应在 中间接口 中完成的



感谢版主的再次指教!谢谢“xuzuning”版主!
我描述的还不够细致,重新描述下业务逻辑:
界面层的功能包括:数据显示,数据编辑请求,操作用户的管理等,且界面层有操作用户的数据库。
中间接口层:处理界面层的请求,无视操作用户,不管哪个操作用户的操作请求,中间接口层都视为合法。

我感觉版主您的意思是在中间接口层处理,然后不管谁发过来的请求,请求过来,标识锁定,返回结果后再标识解锁?
我之前也是这样认为的,因为第一次接触php, 对方是老手,所以不敢确定。

对方非得要我在界面层来处理该业务,说用ajax就可以, 但我觉得我无法去设标识,所以困惑,才有此问。

再次感谢版主的指教!

放在 中间层 比较合适
因为一般的说,中间层就是通常说的 API 
加一个过滤条件比较简单

当然在界面层也可以实现,不过界面层不宜(不能)直接访问数据层。
所以要单独设置缓存机制,未处理完的就不再向中间层发请求
用一个共享内存或数据库或文件的队列就可以了

放在 中间层 比较合适
因为一般的说,中间层就是通常说的 API 
加一个过滤条件比较简单

当然在界面层也可以实现,不过界面层不宜(不能)直接访问数据层。
所以要单独设置缓存机制,未处理完的就不再向中间层发请求
用一个共享内存或数据库或文件的队列就可以了



太感谢了,清晰很多了,谢谢!!!
结贴,呵呵。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to access JSONNode's JSON fields, arrays and nested objects in Java? How to access JSONNode's JSON fields, arrays and nested objects in Java? Aug 30, 2023 pm 11:05 PM

A JsonNode is Jackson's JSON tree model that can read JSON into JsonNode instances and write JsonNode into JSON. We can use Jackson to read JSON into a JsonNode by creating an ObjectMapper instance and calling the readValue() method. We can access fields, arrays or nested objects using the get() method of the JsonNode class. We can use the asText() method to return a valid string representation and convert the node's value to Javaint using the asInt() method of the JsonNode class. In the example below we can access Json

iOS 17: How to control which apps can access your photos iOS 17: How to control which apps can access your photos Sep 13, 2023 pm 09:09 PM

In iOS17, Apple has more control over what apps can see in photos. Read on to learn how to manage app access by app. In iOS, Apple's in-app photo picker lets you share specific photos with the app, while the rest of your photo library remains private. Apps must request access to your entire photo library, and you can choose to grant the following access to apps: Restricted Access – Apps can only see images that you can select, which you can do at any time in the app or by going to Settings &gt ;Privacy & Security>Photos to view selected images. Full access – App can view photos

Access metadata of various audio and video files using Python Access metadata of various audio and video files using Python Sep 05, 2023 am 11:41 AM

We can access the metadata of audio files using Mutagen and the eyeD3 module in Python. For video metadata we can use movies and the OpenCV library in Python. Metadata is data that provides information about other data, such as audio and video data. Metadata for audio and video files includes file format, file resolution, file size, duration, bitrate, etc. By accessing this metadata, we can manage media more efficiently and analyze the metadata to obtain some useful information. In this article, we will take a look at some of the libraries or modules provided by Python for accessing metadata of audio and video files. Access audio metadata Some libraries for accessing audio file metadata are - using mutagenesis

How to solve the problem of inaccessibility after Tomcat deploys war package How to solve the problem of inaccessibility after Tomcat deploys war package Jan 13, 2024 pm 12:07 PM

How to solve the problem that Tomcat cannot successfully access the war package after deploying it requires specific code examples. As a widely used Java Web server, Tomcat allows developers to package their own developed Web applications into war files for deployment. However, sometimes we may encounter the problem of being unable to successfully access the war package after deploying it. This may be caused by incorrect configuration or other reasons. In this article, we'll provide some concrete code examples that address this dilemma. 1. Check Tomcat service

What to do if shared folders cannot be accessed in Windows 10 Home Edition What to do if shared folders cannot be accessed in Windows 10 Home Edition Jan 11, 2024 pm 07:36 PM

Sharing folders is indeed an extremely useful feature in a home or business network environment. It allows you to easily share folders with other users, thereby facilitating file transfer and sharing. Win10 Home Edition shared folder cannot be accessed Solution: Solution 1: Check network connection and user permissions When trying to use Win10 shared folders, we first need to confirm whether the network connection and user permissions are normal. If there is a problem with the network connection or the user does not have permission to access the shared folder, it may result in inaccessibility. 1. First, please ensure that the network connection is smooth so that the computer and the computer where the shared folder is located are in the same LAN and can communicate normally. 2. Secondly check the user permissions to confirm that the current user has permission to share files.

How to solve the problem of access denied when modifying files in Windows 7 How to solve the problem of access denied when modifying files in Windows 7 Jul 04, 2023 pm 07:01 PM

How to solve the problem of access denied when modifying files in win7? When modifying some system files, we will often be prompted that we do not have permission to perform the operation. We can turn off the folder permissions or obtain administrator rights. For users who need to modify such files, let’s take a look at the following specific tutorials. Solution to the problem of access denied when modifying files in win7: 1. First select the corresponding folder, click the tool above, and select the folder option. 2. Enter the View tab. 3. Uncheck Use Simple File Sharing and confirm. 4. Then right-click the corresponding folder and click Properties. 5. Enter the Security tab. 6. Select the icon position and click Advanced. 7

How to solve external resource access and calls in PHP development How to solve external resource access and calls in PHP development Oct 08, 2023 am 11:01 AM

How to solve the problem of accessing and calling external resources in PHP development requires specific code examples. In PHP development, we often encounter situations where we need to access and call external resources, such as API interfaces, third-party libraries or other server resources. When dealing with these external resources, we need to consider how to access and call safely while ensuring performance and reliability. This article describes several common solutions and provides corresponding code examples. 1. Use the curl library to call external resources. Curl is a very powerful open source library.

Allow camera device access only in HTML5 Allow camera device access only in HTML5 Sep 22, 2023 pm 11:09 PM

There is no unique access to the camera device in iOS. The official specification recommendation is as follows - User agent implementations of this specification are recommended to ask for user consent before starting to capture content through the microphone or camera. This may be necessary to meet regulatory, legal and best practice requirements related to user data privacy. Additionally, user agent implementations are recommended to provide an indication to the user when an input device is enabled and to enable the user to terminate such capture. Likewise, user agents are recommended to provide user controls, such as allowing the user to select the exact media capture device to use if multiple devices are present. Disable sound capture in video capture mode.

See all articles