下面的代码运行良好,直到我在 Json 数组中存储了大约 25000-30000 个对象。然后文件不再更新。
有人知道可能是什么问题吗?
foreach ($serials as $key => $serial_list) {
foreach ($serial_list as $key => $serial) {
$url = 'json/voltage/voltage_' . $serial . '.json';
$file = file_get_contents($url, true);
if ($file != true) {
$sql = "SELECT * FROM realtimedata_V WHERE device_serial ='{$serial}' ORDER by timeStamp ASC limit 1200 ";
$result = $db->mysqli->query($sql);
while ($row = $result->fetch_assoc()) {
$voltage_tmp[$serial][] = array(
(int) strtotime($row['timeStamp']) * 1000,
(int) $row['Va'],
(int) $row['Vb'],
(int) $row['Vc']
);
}
echo '<hr>';
echo 'new_datas_' . $serial . '= ' . json_encode($voltage_tmp[$serial]);
echo '<hr>';
file_put_contents($url, json_encode($voltage_tmp[$serial]));
} else {
$data = json_decode($file, true);
if ($data === NULL)
die('Unable to decode');
unset($file);
$AllKeys = array_keys($data);
echo '<hr> Last_Key= <hr>';
echo $last_index = end($AllKeys);
echo '<hr>';
$key = $data[$AllKeys[$last_index]];
$key_unix = $key[0]/1000;
$limit_sql = $last_index +2000;
echo '<hr>';
echo 'Last_date ' . $serial . '= ' . $last_date = date('Y-m-d H:i:s', $key_unix);
echo '<hr>';
echo $sql = "SELECT * FROM realtimedata_V WHERE device_serial ='{$serial}' AND timeStamp > '{$last_date}' ORDER by timeStamp ASC limit {$limit_sql} ";
$result = $db->mysqli->query($sql);
$row_cnt = $result->num_rows;
if ($row_cnt === 0) {
echo 'rows = ' . $row_cnt;
echo '<hr>Any new datas for the serial N°: ' . $serial . '<hr>';
continue;
} else {
while ($row = $result->fetch_assoc()) {
$voltage[$serial][] = array(
(int) strtotime($row['timeStamp']) * 1000,
(int) $row['Va'],
(int) $row['Vb'],
(int) $row['Vc']
);
}
$result = $data + $voltage[$serial];
echo '<hr>';
echo 'new_datas_' . $serial . '= ' . $new_data = json_encode($result);
echo '<hr>';
if (file_put_contents($url, $new_data) === false) {
die('unable to write file');
}
unset($result);
file_put_contents($url, $new_data, LOCK_EX);
//$result->free();
}
}
}
}
在内存限制的情况下,我更改了 php.ini 的配置。但什么都没有......
我在另一台服务器上试过,但同样的问题。有人有想法吗?
谢谢