This article mainly introduces how PHP inserts mysql Data to implement multi-host mutual lock, including the complete implementation methods of locking and Releasing locks, which are very practical. For more information, see
This article mainly introduces how PHP inserts mysql Data to implement multi-host mutual lock, including the complete implementation methods of locking and Releasing locks, which are very practical. For more information, see
This article describes how PHP inserts mysql Data to implement multi-host lock. The specific implementation method is as follows:
You can add a general lock before executing the process. The shell yoke function is as follows. If it succeeds, 0 is returned; otherwise, a non-0 value is returned:
The Code is as follows:
Function get_lock ()
{
Local dataId = "$ {1 }"
Local dataDate = "$ {2 }"
Local SQL = "insert into t_trans_lock
(DataId, dataDate) values ('$ {dataId}', '$ {dataDate }');"
Echo $ {SQL} | $ {DB_PUBLIC}
Return $?
}
Release the lock when execution fails or ends.
The Code is as follows:
Function free_lock ()
{
Local dataId = "$ {1 }"
Local dataDate = "$ {2 }"
Local status = "$ {3 }"
Local SQL = "delete from t_trans_lock
Where dataId = '$ {dataId}' and dataDate = '$ {dataDate }';"
Echo $ {SQL} | $ {DB_PUBLIC}
If [$? -Ne 0]; then
Write_log $ {dataId} "free lock failed"
Fi
Return $ {status}
}
I hope this article will help you design the PHP + MySQL program.