php页面脚本没结束,长时间运行的后台PHP脚本会阻止其他PHP页面,直到完成为止...

我在PHP中制作了一个长脚本:

ignore_user_abort(true);

set_time_limit(0);

即使我关闭页面,它也能在后台完美运行.我的问题是,在此脚本在后台运行之前,我无法打开其他PHP文件.我怎么解决这个问题?

解决方法:

当PHP脚本使用会话时,PHP会锁定会话文件,直到脚本完成.尝试使用锁定会话的页面请求将被阻止,直到会话文件被释放. PHP执行此操作以使会话保持一致状态. Quote from PHP bug #31464:

[2005-01-10 08:13 UTC] derick at php dot net

This is indeed not a bug at all, the session extension needs to lock

the session file so that concurrent updates can not corrupt the file.

This means that all scripts using the same session file needs to be

serialized. To improve performance you can use

07001 as soon as you are done

reading/setting session variables, which will remove the lock of the

file.

如上所述和here as well最简单的解决方法是:

>调用session_start()

>读/写任何会话变量

>调用session_write_close()

>做冗长的处理

标签:php,session,background-process

来源: https://codeday.me/bug/20190926/1818948.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值