直接上代码:
//提交加锁lock $goldlock = dirname(dirname(dirname(__FILE__))).'/cache/gold.lock'; while (file_exists($goldlock)) { $goldlock_time = @filemtime($goldlock); if ($goldlock_time && (time()-$goldlock_time >=5)) { @unlink($goldlock); } usleep(rand(100, 500)); } touch($goldlock); # 业务代码... @unlink($goldlock);//释放锁