PHP致命错误:在GCP平台上调用未定义的函数curl_init()

问题描述 投票:0回答:1

我想使用PHP从我的GCP服务器发送推送通知。我使用以下功能来实现这一目标。当我在本地Xampp Server中运行相同的脚本时,它工作正常。但是,当我在GCP服务器上部署时,它给出了错误。

PHP致命错误:在]中调用未定义的函数curl_init()>

function sendMessage($appId,$userId){
    $content = array(
                     "en" => "Welcome ",
                     );

    $fields = array(
                    'app_id' => $appId,

                    'include_player_ids' => [$userId],

                    'contents' => $content,

                    ); 


    $fields = json_encode($fields);
    print("\nJSON sent:\n");
    print($fields);

    $ch = curl_init(); // Showing error here
    curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                                               'Authorization: Basic xxxxxxx'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

任何人都可以帮助我解决此错误。

我想使用PHP从我的GCP服务器发送推送通知。我使用以下功能来实现这一目标。当我在本地Xampp Server中运行相同的脚本时,它工作正常。但是,当我部署...

php google-cloud-platform onesignal
1个回答
0
投票

添加下一个PHP代码以检查$ ch = curl_init()之前是否启用了curl。

© www.soinside.com 2019 - 2024. All rights reserved.