php 对数据库写入的响应缓慢
我的 PHP 脚本在 WAMP 服务器上运行。 这是我正在做的
- PHP 脚本 A,它查询数据库并获取一组行(我已经设置了 set_time_limit (0) // 脚本执行的无限时间)
- 基于结果集,我为每一行执行一个 tcl 脚本结果集的
- TCL 脚本执行大约需要一分钟,它还会将一些数据插入同一个数据库
- 现在,当 TCL 脚本执行时,如果我执行另一个写入数据库的 PHP 脚本,我将无法这样做是因为响应时间太慢。 事实上,它等待 PHP 脚本 A/TCL 脚本完成
- 但是在此期间,从数据库读取数据很好而且很快
有人有什么建议吗?
问候, 米敦
I have my PHP scripts running on the WAMP server.
Here's what i am doing
- PHP script A that queries the database and gets a set of rows (I have set the set_time_limit (0) // unlimited time for the script to execute )
- Based on the result set I execute a tcl script for each row of the result set
- The TCL script takes about a minute to execute , it also inserts some data to the same database
- Now simultaneously when the TCL script is executing , if i execute another PHP script that writes in to the database , I am not able to do it as the response time is too slow. It infact waits for the PHP script A/TCL script to complete
- However during this time, reads from the database is fine and quick
Does anyone has any suggestions ?
Regards,
Mithun
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
会话不能被并发脚本共享。 任何尝试
session_start()
的新请求都将在此时挂起,等待上一个脚本结束。由于您的脚本需要不确定的时间才能结束,因此最好
session_write_close()< /code> 从 $_SESSION 超全局获取所需的所有信息后,因此并发请求将不再挂起。
A Session cannot be shared by concurrent scripts. Any new requests which try to
session_start()
will hang at this point waiting for the previous script end.As your script is taking undetermined time to end, its a good idea to
session_write_close()
right after obtaining all information it needs from the $_SESSION superglobal, so concurrent requests won't hang anymore.