允许运行 php 脚本的多个实例

发布于 2024-09-10 06:02:43 字数 166 浏览 2 评论 0原文

我正在尝试使用 ajax 对 php 脚本同时发出多个请求,但是,它似乎一次只执行 1 个实例,并且在前一个调用完成之前我无法连接以执行下一个调用。我必须做什么才能让它同时完成所有这些工作?我在 Windows 上使用 apache (xampp)。我还在我的 unix 服务器上测试了这一点,同样的事情也发生在那里。

I'm trying to use ajax to make multiple simultaneous requests to a php script, however, it only seems to do 1 instance at a time and I cannot connect to do the next call until the previous one is finished. What do I have to do in order to make it do them all at the same time? I'm using apache (xampp) on windows. I've also tested this on my unix server and the same thing is happening there as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情域 2024-09-17 06:02:43

从理论上讲,没有什么可以阻止一个 PHP 脚本并行执行多次 - 否则,很多网站都会出现大问题;-)

因此,在您的情况下,可能存在某种锁定机制来防止这种情况发生。 那么,

If your script is using sessions, and those are file-based *(which is the default)*, those sessions could cause that kind of problem : with the default session handler, it's not possible to have several files accessing the same session data *(i.e. the session data that corresponds to a given user)* at the same time ; that's to prevent one script from overriding the data of another, and should probably not be disabled.

如果您的脚本正在使用会话:您可以停止使用会话吗?

如果没有,您应该在不需要它们时立即尝试关闭它们——以解锁用于存储它们的文件。

这是 session_write_close,关于那个:

会话数据通常存储在
你的脚本终止没有
需要调用session_write_close(),
但由于会话数据被锁定
防止并发只写一个
脚本可以随时在会话上运行
时间。
使用框架集时
与会议一起,您将
体验逐帧加载
由于这种锁定。
你可以
减少加载所有内容所需的时间
尽快结束会话来构建框架
作为会话变量的所有更改
完成了。


In theory, there is nothing preventing one PHP script from being executed several times in parallel -- else, a lot of websites would have big problems ;-)

So, there is probably, in your situation, some locking mecanism that prevents this...

If your script is using sessions, and those are file-based *(which is the default)*, those sessions could cause that kind of problem : with the default session handler, it's not possible to have several files accessing the same session data *(i.e. the session data that corresponds to a given user)* at the same time ; that's to prevent one script from overriding the data of another, and should probably not be disabled.

So, if your script is using sessions : would it be OK for you to stop using sessions ?

If not, you should try to close them as soon as you don't need them -- to unlock the files that are used to store them.

Here's a quote from the manual page of session_write_close, about that :

Session data is usually stored after
your script terminated without the
need to call session_write_close(),
but as session data is locked to
prevent concurrent writes only one
script may operate on a session at any
time
.
When using framesets
together with sessions you will
experience the frames loading one by
one due to this locking.
You can
reduce the time needed to load all the
frames by ending the session as soon
as all changes to session variables
are done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文