"hello world!"], "school"); $this->success('返回成功', $this->request->param()); } /** * 无需登录的接口 * */ public function test1() { try{ $lock = new UrlLock(1,"mock-create-lock-suffix",120,"您的请求过于频繁,请您稍后再试!请求最大锁定间隔5秒/一次!"); $lock->lock(); //往缓存里取出数字 $num = cache('test'); if(!$num){ $num = 1; cache('test',$num); }else{ $num++; cache('test',$num); } //数字加1 //再存入缓存 //再写入test.txt文件末尾(记得回车换行) file_put_contents("test.txt",$num."\r\n",FILE_APPEND); }catch (\Throwable $e){ $lock->free(); // file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试 $this->error($e->getMessage()); } $lock->free(); $this->success('返回成功', ['action' => 'test1']); } /** * 需要登录的接口 * */ public function test2() { try{ $lock = new UrlLock(1,"mock-create-lock-suffix",120,"您的请求过于频繁,请您稍后再试!请求最大锁定间隔5秒/一次!"); $lock->lock(); var_dump(time()); sleep(5); }catch (\Throwable $e){ $lock->free(); // file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试 $this->error($e->getMessage()); } $lock->free(); $this->success('返回成功', ['action' => 'test1']); } /** * 需要登录且需要验证有相应组的权限 * */ public function test3() { $this->success('返回成功', ['action' => 'test3']); } }