I’m trying to send a POST request in server to fcm.googleapis.com/fcm/send but curl return false after amount of time.
$url = 'https://fcm.googleapis.com/fcm/send';
// Set the FCM server key for your Firebase project
$server_key = '<FCM server key>';
// Prepare the message payload in JSON format
$message = array(
'to' => '<FCM token>',
'notification' => array(
'title' => 'New Message',
'body' => 'Hello, this is a test message'
)
);
$fields = json_encode($message);
// Set the cURL request headers
$headers = array(
'Authorization: key=' . $server_key,
'Content-Type: application/json'
);
$ch = curl_init();
// Set the cURL options
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);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, false);
// Execute the cURL request
$result = curl_exec($ch);
The value of $resulat will be false after call.
I tried openssl s_client -connect fcm.googleapis.com:443
and it just return CONNECTED and nothing else.
and also curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);