userId = $userId; } /** * Execute the job. * * @return void */ public function handle() { $table = 'ocr_images'; // status 0 未执行 2 已完成 3 失败 DB::table($table)->where('status', 0)->where('user_id', $this->userId) ->lazyById()->each(function ($img) use ($table) { $imagePath = public_path($img->path); $cmd = 'hub run chinese_ocr_db_crnn_server --input_path "' . $imagePath . '"'; $result = exec($cmd); $re = preg_replace("/\'/", "\"", $result); $result = json_decode($re, true); if (empty($result)) { // 失败 DB::table($table)->where('id', $img->id)->update(['status' => 2, 'result' => $result]); } else { // 成功 DB::table($table)->where('id', $img->id)->update(['status' => 3]); } }); } }