Using (FCM) Firebase Cloud Messaging you can send the real time notification to the browser in your PHP web application , Using FCM, you can notify a client that new event or other data or mail is available to sync.
![](http://findnerd.s3.amazonaws.com/imagedata/9178/9178.png)
To send the notification you need to get the FCM Token From User. After you get the token now we will send the notification using following script.
Note :- You can get the API key after sign up from https://console.firebase.google.com/
// declare the array for notification message
$param = [];
$params['notification']['notification_title'] = 'Title';
$params['notification']['notification_body'] = 'Body';
$params['notification']['notification_click_action'] = 'Click Action';
$params['to'] = "<Firebase Token>"; // use your firebase token here
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = json_encode($params);
set the header
$headers = array(
'Authorization: key=' . "<your api key>",
'Content-Type: application/json'
);
// create the curl request to send the push notification
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch);
0 Comment(s)