yii2 - yii2 queue - save to db and log not working within curl job

半城伤御伤魂 提交于 2020-12-15 05:47:22

问题


I am using https://github.com/yiisoft/yii2-queue

I have function in execute method in queue class like:

$this->RegisterDomains($available,$registrar->end_point, $this->request_id,$model->user_id,$registrar->api_key);

and the registerDomains function looks like this:

public function RegisterDomains($available,$end_point,$request_id,$user_id,$api_key)
    {
        
        $model = CatchDomains::find()->where(['request_id'=>$request_id])->one();
        $PathToLog = 'runtime/domaincatch';
     
       if(!(is_array($available['domain']))){         
         $domain_list = $available["domain"];
         $url = $end_point."registerDomain?version=1&type=xml&key=$api_key&domain=$domain_list&years=1";
        
         $ch = curl_init();
             
             $LogFileHandle1 = fopen($PathToLog."/register.log", "a+");
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_VERBOSE, true);
             curl_setopt($ch, CURLOPT_POST, true); 
             curl_setopt( $ch,CURLOPT_RETURNTRANSFER,true); 
             curl_setopt($ch, CURLOPT_STDERR, $LogFileHandle1);
             $result = curl_exec($ch);
             $xml = simplexml_load_string($result, "SimpleXMLElement", LIBXML_NOCDATA);
             $json = json_encode($xml);
             $response = json_decode($json,TRUE);
             $model->result=$result;
             $model->response = $json;
             $model->save();               
             curl_close($ch);
             echo $result;
        }

when I am executing yii queue/run from console. The function is executing fine & no error is shown there. but nothing is saved in database for my model->save() or nothing is written in register.log but if I am running the function without queue both this works fine.

来源:https://stackoverflow.com/questions/65036998/yii2-yii2-queue-save-to-db-and-log-not-working-within-curl-job

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!