允许运行 php 脚本的多个实例
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从理论上讲,没有什么可以阻止一个 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
,关于那个: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 :