问题
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