我正在开发一个脚本来检查托管平台上不同服务的状态,它将状态发送到每个服务的数据库(0:在线/1:功能失调/2:离线/3:未知)。
我收到以下错误:注意:未定义索引:在第 164 行的 /home/cuonicco/public_html/olympe/inc/updatestatus.php
这是代码,我删掉了一些部分(其他 3 个不同的验证):
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$info = array();
$data = array();
$mysqli = new mysqli("*********", "*********", "*********", "*********");
$query = $mysqli->prepare("SELECT name, status FROM olympe");
$query->bind_result($name, $status);
$query->execute();
$query->store_result();
$count = $query->num_rows;
if($count > 0)
{
while($query->fetch())
{
$info[$name]['status'] = $status;
}
}
$query->close();
// Verification Panel :
$panel = curl_init("https://hosting.olympe.in/login");
curl_setopt($panel, CURLOPT_TIMEOUT, 10);
curl_setopt($panel, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($panel, CURLOPT_HEADER, FALSE);
curl_setopt($panel, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($panel);
$http_status = curl_getinfo($panel, CURLINFO_HTTP_CODE);
curl_close($panel);
if($http_status == 200)
{
$data['panel']['status'] = 0;
}
elseif($http_status == 500)
{
$data['panel']['status'] = 1;
}
else
{
$data['panel']['status'] = 2;
}
// Verification HTTP :
$http = curl_init("http://cuonic.olympe.in/status/test-http.php");
curl_setopt($http, CURLOPT_TIMEOUT, 10);
curl_setopt($http, CURLOPT_HEADER, FALSE);
curl_setopt($http, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($http);
$http_status = curl_getinfo($http, CURLINFO_HTTP_CODE);
curl_close($http);
if($http_status == 200)
{
$data['http']['status'] = 0;
}
else
{
$data['http']['status'] = 2;
}
// More verification functions...
// ....
// Database updating :
$array_count = count($data);
$i = 0;
while($i <= $array_count)
{
$name = key($data);
$array = current($data);
if($info[$name]['status'] != $data[$name]['status']) // Error occurs here
{
$query = $mysqli->prepare("INSERT INTO log (name, previous, latest) VALUES (?, ?, ?)");
$query->bind_param("sii", $name, $info[$name]['status'], $data[$name]['status']);
$query->execute();
$query->close();
}
$query = $mysqli->prepare("UPDATE olympe SET status = ? WHERE name = ?");
$query->bind_param("is", $data[$name]['status'], $name);
$query->execute();
$query->close();
next($data);
$i++;
}
?>
究竟是什么原因造成的,整天困扰着我。我已经在“错误行”之前回显了数组的值,它们都存在。
提前致谢 :)