* @since 2.0 */ class ScriptWhileOrderController extends Controller { public static $cx_mch_id=0; /** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. * @return int Exit code */ public function actionIndex() { $redis_name_lock = "cxaibc:console:ScriptWhileOrderController_v4"; try { $get = \Yii::$app->redis->setnx($redis_name_lock,1); if(empty($get)){ var_dump("脚本正在执行中"); exit(); } // 执行体 $redis_name = "cxgyc:YopointNotify:list"; $arr = []; $yopoint_obj = new YopointApi(); while(true){ sleep(1); $get = \Yii::$app->redis->rpop($redis_name); if(empty($get)){ break; } $res = $yopoint_obj->syncOrder($get); if(empty($res)){ continue; } $arr[] = $res; } foreach ($arr as $key=>$val){ // 重新写入 \Yii::$app->redis->lpush($redis_name,$val); } \Yii::$app->redis->del($redis_name_lock); }catch (\Exception $e){ \Yii::$app->redis->del($redis_name_lock); var_dump($e->getMessage()); } echo "1分钟脚本"; exit(); } }