load->model('Import_model'); $this->data['nav'] = 'index'; $this->data['nav_header'] = $this->load->view('index/order_header', '', true); } public function index() { echo '从汉特导入订单'; } //检查是否有新订单 public function sync() { //加上文件锁,保障同步过程同一时间运行一次 define("LOCK_FILE_PATH", sys_get_temp_dir()."/lock.orders"); if (!file_exists(LOCK_FILE_PATH)) { $fp = fopen(LOCK_FILE_PATH, "w"); fclose($fp); } $fp = fopen(LOCK_FILE_PATH, "r"); if (!$fp) { echo "Failed to open the lock file!"; exit(1); //异常处理 } flock($fp, LOCK_EX); //此处添加原子操作代码 @set_time_limit(0); $data = array(); $this->Import_model->tour(); $this->Import_model->business(); $this->load->view('header', $this->data); $this->load->view('import_orders'); $this->load->view('footer'); //此处添加原子操作代码 end flock($fp, LOCK_UN); fclose($fp); } }