服务器使用laravel队列时内存不足
我的应用程序使用了laravel lumen 5.5 api。我已创建用于向用户发送通知的作业队列。此通知可以随时从管理员发送,管理员将创建4或5个通知并发布给用户。 我有下面这个工作的代码服务器使用laravel队列时内存不足,laravel,laravel-5,queue,lumen,Laravel,Laravel 5,Queue,Lumen,我的应用程序使用了laravel lumen 5.5 api。我已创建用于向用户发送通知的作业队列。此通知可以随时从管理员发送,管理员将创建4或5个通知并发布给用户。 我有下面这个工作的代码 //Creating queue job logic in my API Controller $message = $request->input('message'); $notifyrequest = new NotificationJob(); $notifyrequest->setme
//Creating queue job logic in my API Controller
$message = $request->input('message');
$notifyrequest = new NotificationJob();
$notifyrequest->setmessage($message, $request->input('title'));
dispatch($notifyrequest);
return array('error' => false, 'message' => 'Notification sent successfully.');
//Notificaiton Job logic in job folder class
class NotificationJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $message;
protected $title;
/**
*/
public function __construct()
{}
public function setmessage($message, $title){
$this->message = $message;
$this->title = $title;
}
public function handle()
{
Log::info("Request Push Notificaiton Queues Handle".$this->message, ['title' => $this->title]);
$Onesignalnotification = new Onesignalnotification();
$onesignalresponse = $Onesignalnotification->sendNotification($this->message, $this->title);
Log::info("Notification has been sent", ['Response' => $onesignalresponse]);
}
}
//Sending notifications through one signal. Using filter for active users to receive notification. Currently 10K+ users are there.
public function sendNotification($message, $title)
{
$content = array(
"en" => $message
);
$hashes_array = array();
$fields = array(
'app_id' => $this->APP_ID,
'included_segments' => array('Active Users'),
'data' => array(
"nav" => "1"
),
'contents' => $content,
'web_buttons' => $hashes_array
);
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic apikey'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$return["allresponses"] = $response;
$return = json_encode($return);
$data = json_decode($return, true);
return $data;
}
我在后台过程中使用了supervisor,我的supervisor程序如下所示:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=4
redirect_stderr=true
stdout_logfile=/tmp/supervisor_worker.log
而且也试过下面这样的方式
1.command=php /var/www/html/artisan queue:work redis --sleep=3 --tries=3 --daemon
2.command=php /var/www/html/artisan queue:work redis --sleep=3 --tries=3 --once --daemon
3.command=php /var/www/html/artisan queue:listen redis --sleep=3 --tries=3
4.command=php /var/www/html/artisan queue:listen redis --sleep=3 --tries=3 --daemon
但是仍然有一个关于记忆的问题。它是第一次发送通知,如果下一次更新后意味着在挂起后发送通知,则会产生内存泄漏。我的服务器已进入未响应状态。使用gc\u collect\u循环或定期重新启动进程(crontab)。它将释放您的内存您是否尝试将
MemoryUsageProcessor
添加到Monog实例以检查内存使用情况?你知道它在哪里内存不足吗?你的服务器规格是什么。多少GB的内存和CPU的数量?。还可以添加laravel和supervisord?CentOS 7 64位2 GB Ram的错误日志。在supervisor和laravel中,我找不到与此相关的任何错误。我的队列在显示http不再响应的服务器之后执行。如果我重新启动服务器,意味着我的域开始工作。如果我的域名不起作用,有什么帮助或想法吗?