<?php

function toHook($event, $params = null, bool $once = false)
{
    $url = "http://www.site1.com/index.php/index/hook";
    $post_data = [
        'event' => $event,
        'params' => $params,
        'once' => $once,
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    if (!$output) $output = 'Curl error: ' . curl_error($ch);
    curl_close($ch);
    return $output;
}

function toHook2($event, $params = null, bool $once = false)
{
    $params = is_string($params) ? $params : json_encode($params);
    $url = "http://www.site1.com/index.php/index/hook?event{$event}&$params={$params}&once={$once}";

    //初始化一个curl会话
    $ch = curl_init();
    //初始化CURL回话链接地址，设置要抓取的url
    curl_setopt($ch, CURLOPT_URL, $url);
    //对认证证书来源的检查，FALSE表示阻止对证书的合法性检查
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    //从证书中检查SSL加密算法是否存在
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    //设置将获得的结果是否保存在字符串中还是输出到屏幕上，0输出，非0不输出
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //执行请求，获取结果
    $result = curl_exec($ch);
    //关闭会话
    curl_close($ch);

    //反馈结果
    return $result;
}