*/ require_once(APP_PATH."/protected/vendor/autoload.php"); use Qiniu\Auth; use Qiniu\Storage\BucketManager; class AsyncWorkCommand extends CConsoleCommand{ public function run($args) { error_reporting(E_ALL); ini_set('memory_limit', '512M'); ignore_user_abort(true); set_time_limit(0); $time_H = time(); while (true) { sleep(3); $time = time(); if($time - $time_H > 3600){ exit(); } //用户注册后异步任务 $list = new ARedisList('after_user_reg'); $auth = new Auth(Yii::app()->params['qiniuConfig']['ak'],Yii::app()->params['qiniuConfig']['sk']); $bmgr = new BucketManager($auth); while ($list->getCount() > 0) { $user_id = $list->pop(); try { $userAr = RUser::get(new MongoId($user_id)); //抓取头像到七牛 $url = $userAr->avatar; if(strpos($url,'qiniu')===false){ $bucket = Yii::app()->params['qiniuConfig']['avatars']; $key = dechex(time()).rand(10,99).'.jpg'; list($ret, $err) = $bmgr->fetch($url, $bucket, $key); echo "=====> fetch $url to bucket: $bucket key: $key\n"; if ($err !== null) { file_put_contents(APP_PATH.'/download/log/after_user_reg.log',var_export($err,true),FILE_APPEND); } else { if(YII_DEBUG == true){ $userAr->avatar = 'http://odujh0tsx.bkt.clouddn.com/'.$key; }else{ $userAr->avatar = 'http://odulcd8g1.bkt.clouddn.com/'.$key; } } } $userAr->update(array('avatar'),true); } catch (Exception $e) { var_dump($e); continue; } } //订单支付成功后异步任务 $list = new ARedisList('o2o_after_pay_success'); while ($list->getCount() > 0) { $res = $list->pop(); $input_data = json_decode($res,true); try { $order = ROrder::get(new MongoId($input_data['order_no'])); CommonFn::sendOrderSms($order,$input_data['id']); } catch (Exception $e) { continue; } } //发送短信异步任务 $list = new ARedisList('send_sms_list'); $smsservice = Service::factory('SendSMSService'); while ($list->getCount() > 0) { $key = $list->pop(); try { $sms_data = json_decode($key,true); $smsservice->send_sms($sms_data['tpl'],$sms_data['mobile']); } catch (Exception $e) { continue; } } } } }