如何在PHP中创建非文件锁? [英] How can I create a non-file lock in PHP?

查看:71
本文介绍了如何在PHP中创建非文件锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP维护脚本,用于更新和修复数据库.从理论上讲,同时运行两个脚本不是问题,但是我想通过在PHP变量中加一个锁来提高安全性.当然,问题在于我无法将其存储在$_SESSION变量中,因为会话仅适用于一个用户.

I have a maintenance script in PHP that updates and repairs the database. In theory, running two scripts simultaneously shouldn't be a problem, but I want to be extra safe by putting a lock in a variable in PHP. The problem, of course, is that I can't store it in a $_SESSION variable because sessions only apply to one user.

有什么方法可以将此锁存储在变量中?我宁愿不要创建和删除文件,以防服务器在脚本中间死掉.

Is there any way I can store this lock in a variable? I'd prefer to not create and delete a file in case the server dies in the middle of the script.

推荐答案

MySQL具有 GET_LOCK()函数.

MySQL has GET_LOCK() function.

这篇关于如何在PHP中创建非文件锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆