2016-12-20 4 views
1

Ich versuche FCM in Laravel mit Curl zu verwenden, aber ich bekomme Fehler. Zuerst habe ich in einem meiner cotroller ein PHP-Code geschrieben, das ist:Laravel 5.2 curl_init() Wurffehler "Call to undefined Funktion"

$first_name = $request->input('first_name'); 
     //FCM api URL 
     $url = 'https://fcm.googleapis.com/fcm/send'; 
     //api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key 
     $server_key = 'AIzaSyA1RyuAGGPASh_flFCwiyd9ZHEMYlhQOho'; 
    $target = "r_token"; 
     $fields = array(); 
     $fields['data'] = $first_name; 
     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; 

Und ich versuche diesen Code in meinem Controller Laravel 5.2 zu laufen, aber ich bin immer diese Fehlermeldung:

FatalErrorException in WebKyoController.php line 52: 
    Call to undefined function App\Http\Controllers\curl_init() 

Ich habe versucht: sudo apt-get install php-curl und apache neu starten, aber immer noch bekomme ich Fehler. Ich möchte nur wissen, was ich tun muss.

+0

hast du auch versucht 'sudo apt-get install curl 'auch sagen, Ihre Bedienung und Version? – Qazi

+0

Nein, ich habe nicht versucht, dieses Sudo apt-get install curl Ich benutze Ubuntu 14.04. Es sagt, Curl ist bereits installiert. –

Antwort

1

Ich fand die Lösung für dieses Problem Ich hatte PHP 7 installiert und es funktionierte nicht. Aber ich habe entfernt php 7 und installiert PHP 5 und dann betreibe ich diese Befehle:

sudo apt-get install curl 
sudo service apache2 restart 
sudo apt-get install php5-curl 
sudo service apache2 restart 

Above Befehle hat den Trick für mich. Ich weiß nicht, warum es nicht funktionierte auf PHP 7

+0

Es geht nicht um Trick, es bedeutet, dass dein Curl-Modul nicht installiert wurde ... und durch obige Befehle ist es installiert – Qazi

+0

Das passiert, weil ich php 7 hatte und ich php5 curl installiert habe –

Verwandte Themen