3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Parameter Example $data = array('post_id'=>'12345','post_title'=>'A Blog post'); $target = 'single tocken id or topic name'; or $target = array('token1','token2','...'); // up to 1000 in one request */ function sendMessage($data, $target){ //FCM api URL $url = 'https://fcm.googleapis.com/fcm/send'; //api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key $server_key = 'AIzaSyDdGQuWaop0NoJd09t4DKLi-Vdt7hQJ0pU'; $fields = array(); $fields['data'] = $data; if(is_array($target)){ $fields['registration_ids'] = $target; }else{ $fields['to'] = $target; } //header with content_type api key $headers = array( 'Content-Type:application/json', 'Authorization:key='.$server_key ); $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_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); if ($result === FALSE) { die('FCM Send Error: ' . curl_error($ch)); } curl_close($ch); return $result; } echo sendMessage(array('message' => 'lol', 'post_title' => 'LOL'), '/topics/news'); ?>
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/v00fv:28 Stack trace: #0 /in/v00fv(44): sendMessage(Array, '/topics/news') #1 {main} thrown in /in/v00fv on line 28
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/v00fv:28 Stack trace: #0 /in/v00fv(44): sendMessage(Array, '/topics/news') #1 {main} thrown in /in/v00fv on line 28
Process exited with code 255.
Output for 5.6.0 - 5.6.27
Fatal error: Call to undefined function curl_init() in /in/v00fv on line 28
Process exited with code 255.

preferences:
199.67 ms | 401 KiB | 235 Q