I am trying to use laravel Queue
I am using the following command to send data to my queue
$data = array(
'from'=> $mailfromname .'<'.$mailfrom.'>',
'to'=>$toname.'<'.$to.'>',
'subject'=>$subject,
'html'=>$html,
'text'=>$text,
'o:tracking'=>'yes',
'o:tracking-clicks'=>'yes',
'o:tracking-opens'=>'yes',
'o:tag'=>$tag,
'h:Reply-To'=>$replyto
);
Than i send the array to my ExampleJob
Queue::push(new ExampleJob($data));
I have than in the in the handle of my job a curl function that accepts the $data
So my problem here is my curl function works fine if i send the emails without using jobs but when i use jobs I see the jobs table being populated and than it processes but no email sends using curl ... anyone know why is that ?
public function handle($data)
{
$session = curl_init(MAILGUN_URL.'/messages');
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_USERPWD, 'api:'.MAILGUN_KEY);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $data);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($session);
curl_close($session);
$results = json_decode($response, true);
return $results
}
您的handle方法的参数是$data
但我只看到正在使用$array_data
。
you need to set the $data
in the constructor of your job, not in the handle function
refer to this example https://laravel.com/docs/5.6/queues#class-structure
public function __construct($data) { $this->data = $data; }
我实际上发现了问题,您看到Curl运行缓慢,因此在que中使用curl时,需要确保为其提供足够的运行时间,因此将队列侦听时间设置为60秒。
php artisan queue:listen --timeout=60
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.