小编Pma*_*max的帖子

如何防止脚本的多个实例?

我有php脚本,我必须在Linux和Windows服务器上运行.我想使用相同的脚本而不对这两个环境进行任何修改.

对于我的Windows环境,这些脚本将使用cron(在linux上)和Windows调度程序(或其他,我现在不关心)进行调度.

但是,某些脚本可能需要几分钟才能完成.我只想防止调度程序(cron或windows的一个)在上次启动它之前启动相同的脚本.

我不知道该怎么做..我想确保在执行期间出现问题时释放"锁定",所以下次没有人为干预时再次启动它.

也许有一个虚拟文件上的羊群可以做到这一点,但我不知道该怎么做.

我在这些服务器上也有一个MySQL数据库.我想可能在数据库端使用锁.

1- Start a transaction
2- Insert script name in a table.
3- execution of the script.
4- If successful then delete the row and commit the transaction or simply rollback;
Run Code Online (Sandbox Code Playgroud)

如果脚本名称在表中,那么我可以阻止它运行.如果脚本执行失败,则Mysql将自动回滚事务,以便下次调用脚本时不显示该行.

但是,在一个事务中,有没有办法让其他连接看到未提交的数据?如果有,怎么样?

如果无法使用回滚的话,我还想过在行上使用锁.

1- Insert script name in a table if it doesn't already exists.
2- Start a transaction.
2- Select * from Table where script_name FOR UPDATE.
3- execution of the script.
4- If successful then release the lock (rollback or commit).
Run Code Online (Sandbox Code Playgroud)

但我的主要问题是Mysql.选择FOR …

php mysql

2
推荐指数
1
解决办法
2551
查看次数

标签 统计

mysql ×1

php ×1