Answer the question
In order to leave comments, you need to log in
Web PUSH notifications not sent via CRON?
The task is to send Web PUSH notifications to users of the site when a certain event occurs. This must be done as quickly as possible (the delay should not be more than 1 minute). Therefore, I decided not to use all sorts of services that provide such an opportunity, but to use the basic solution through Firebase Cloud Messaging, the instructions for
which
are described in detail here The user token is received and stored in the database. Those. permission to receive messages is received, the token is known.
Every minute, cron is launched and executes a php script that, if necessary, sends a message via curl to fcm.googleapis.com/fcm/send (and from there a request is already sent to the browser to display a push notification).
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $control->_connect_ini['google_url']);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);
{
"canonical_ids": 0,
"failure": 0,
"multicast_id": 5652500584254823832,
"results": [
{
"message_id": "0:1527001372290285%2fd9afcdf9fd7ecd"
}
],
"success": 1
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question