防止代码或函数执行一次以上 [英] Prevent Code or Function from Executing More Than Once

查看:97
本文介绍了防止代码或函数执行一次以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使我重新执行(或重新加载)PHP文件,有没有办法防止代码块或代码中的函数多次运行?

Is there a way to prevent a code-block or a function within a code from running more than once even if I re-execute (or reload) the PHP file?

我的意思是,我可以限制某人多次执行php脚本吗?我似乎找不到办法.

I mean, can I restrict someone from executing a php script more than once? I can't seem to find the way to do this.

推荐答案

我有一个可以做到这一点的应用.

I have an app that does that.

我们要做的是在数据库中创建一个名为version的表,并在其中存储一个版本号.脚本运行后,将数据库中的版本号与php脚本中的版本号进行了比较.并执行将其升级"到新版本所需的任何操作,然后更新数据库中的版本号.

What we did was create a table in the db called version, and stored a version number in there. When the script is ran, it compared the version number in the database with that in the php script. And perform whatever it needs to "upgrade" it to the new version, and then updates the version number in the database.

当然,如果版本表不存在,代码将创建它并将其标记为存储版本零.

Of couse, if the version table does not exist, the code will create it and mark it as storing version zero.

这篇关于防止代码或函数执行一次以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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