php怀疑。如果两个人同时访问同一个脚本会发生什么?

时间:2022-05-21 03:49:43

i've made a php search engine a while ago and now i have this doubt that i already searched for it and saw a lot of questions here on stack overflow talking about multiple simultaneous accesses to php scripts but only regarding appending, modifying etc...

我刚刚创建了一个php搜索引擎,现在我怀疑我已经搜索过它并在堆栈溢出中看到很多问题,谈论多个同时访问php脚本但只关于附加,修改等。 。

let's say my search engine (or any other script that based on user input generates different responses) would take 20 seconds to end searching.

假设我的搜索引擎(或基于用户输入的任何其他脚本生成不同的响应)将花费20秒来结束搜索。

user A accesses the script

用户A访问脚本

user B accesses the script 10 seconds later than user A (so the script didn't 'answered' user A yet)

用户B比用户A晚10秒访问脚本(因此脚本尚未“回答”用户A)

what will happen? will the server "execute another instance of the file" and so both users will have their responses or will something be messed up?

会发生什么?将服务器“执行该文件的另一个实例”,这样两个用户都会有他们的回复或者某些事情会搞砸?

also if a php script takes a long time to finish execution and a person accesses it and then leaves without waiting for the response, will the php script still do everything it has to do until it reaches the end? (logic tells me that on this last question the script will do everything until it reaches the end because the person just makes the request, then waits for the answer to come and if it closes still nothing is going to stop the php script from executing, but i'm still asking because i want to be completely sure)

如果一个PHP脚本需要很长时间才能完成执行并且一个人访问它然后离开而不等待响应,那么php脚本是否仍会执行它必须做的所有事情直到它到达终点? (逻辑告诉我,在最后一个问题上,脚本将完成所有操作,直到它到达终点,因为该人只是发出请求,然后等待答案来,如果它关闭仍然没有什么会阻止php脚本执行,但我仍然在问,因为我想完全确定)

2 个解决方案

#1


3  

Both persons have their own instance of your script. There could still be problems concerning data consistency if data is modified. With HTTP being a stateless protocol, you don't know if a person leaves without waiting for the result, the script will run to the end.

两个人都有自己的脚本实例。如果修改数据,仍可能存在数据一致性问题。如果HTTP是无状态协议,您不知道一个人是否离开而没有等待结果,脚本将运行到最后。

#2


0  

every user's session processes with a Threads. every thing is in queue and nothing messes up.

每个用户的会话都使用线程进行处理。每件事都在排队,没有任何事情搞砸了。

but in some conditions problems may occur.

但在某些情况下可能会出现问题。

ex: a user asks for a certain field in DB but another user deletes that field while 1st user's thread is waiting or suspended. but it is really rear and if it happens an exception will be throne and it's our scripts duty to handle it.

例如:用户要求DB中的某个字段,但是另一个用户在第一个用户的线程等待或暂停时删除该字段。但它真的是后方,如果它发生了一个例外将是王位,这是我们的脚本责任来处理它。

#1


3  

Both persons have their own instance of your script. There could still be problems concerning data consistency if data is modified. With HTTP being a stateless protocol, you don't know if a person leaves without waiting for the result, the script will run to the end.

两个人都有自己的脚本实例。如果修改数据,仍可能存在数据一致性问题。如果HTTP是无状态协议,您不知道一个人是否离开而没有等待结果,脚本将运行到最后。

#2


0  

every user's session processes with a Threads. every thing is in queue and nothing messes up.

每个用户的会话都使用线程进行处理。每件事都在排队,没有任何事情搞砸了。

but in some conditions problems may occur.

但在某些情况下可能会出现问题。

ex: a user asks for a certain field in DB but another user deletes that field while 1st user's thread is waiting or suspended. but it is really rear and if it happens an exception will be throne and it's our scripts duty to handle it.

例如:用户要求DB中的某个字段,但是另一个用户在第一个用户的线程等待或暂停时删除该字段。但它真的是后方,如果它发生了一个例外将是王位,这是我们的脚本责任来处理它。