<?php
error_reporting(0);
require_once ('config.php');
$sql = "select * from weather_online";
$result = mysqli_query($conn,$sql);
$i = 1;
while($row = mysqli_fetch_assoc($result)){
    $rthi[$i] = $row;
    $i++;
}
file_put_contents('output.json',json_encode($rthi));
$file = 'file.txt';
$fp = fopen($file, 'rb+');

if(($fp) !== false) {
    if(flock($fp, LOCK_EX) === true) {
        $size = filesize($file);

        if($size > 0) {
            $data = fread($fp, $size);
            echo $data;
            ftruncate($fp, 0);
        } else {
            echo '';
        }

        flock($fp, LOCK_UN);
    } else {
        echo 'Locking Error!';
    }

    fclose($fp);
}
?>