<?php
$apiMonitor = DB::table('sites')->select('uptime_access_code')->get();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.uptimerobot.com/v2/getMonitors",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "api_key=Private&format=json&logs=1&monitors=$apiMonitor&custom_uptime_ratios=1-7-30",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response);
$custom_uptime = ($data->monitors[0]->custom_uptime_ratio);
$uptime = explode("-",$custom_uptime);
}
?>
这是我的显示器;
CURLOPT_POSTFIELDS => "api_key=Private&format=json&logs=1&monitors=778780885&custom_uptime_ratios=1-7-30",
您可以看到的输出已经在工作了,但是如何才能从数据库中获取数据并将正常运行时间\访问\代码的值放入监视器?非常感谢。