|
 |
|
สอบถามหน่อยครับ เรื่อง database(sql) to text โดยบันทึกข้อมูลทุกๆ 30นาที - 1ช.ม. |
|
 |
|
|
 |
 |
|
ดึงข้อมูลจาก database มาต่อสตริง แล้ว ยัดใส่ตัวแปร $content ได้เลยครับ
ส่วนจะให้บันทึกทุกๆ 30 นาที นั้นก็หมายความว่าต้องรันสคริปทุกๆ 30 นาที
ในส่วนนี้ต้องใช้ cron job มาช่วยครับ ถ้าไม่รู้จักลอง search หาข้อมูลดูครับ
ถ้าไม่งั้นต้องเปิด web browser ไว้ตลอดเวลา แล้วใช้ พวก javascript interval ตั้งเวลาครับ
<?php
$content = "ทดสอบ"; //ข้อมูลที่จะเขียนลงไฟล์ text
$folder = "log"; //ชื่อ folder เก็บไฟล์
$dateFile = "date.dat";
$dateFile = $folder."/".$dateFile;
if (!file_exists($folder)) {
mkdir($folder, 0777, true);
}
if (!file_exists($dateFile)) {
file_put_contents($dateFile, date("d-m-Y"));
$today = date("d-m-Y");
}
if(file_get_contents($dateFile)!=date("d-m-Y")){
file_put_contents($folder."/".date("d-m-Y_H.i").".txt", $content."\n");
} else {
file_put_contents($dateFile, date("d-m-Y"));
$files = glob($folder."/*.txt");
foreach($files as $file){
if(is_file($file))
unlink($file);
}
file_put_contents($folder."/".date("d-m-Y_H.i").".txt", $content."\n");
}
?>
|
 |
 |
 |
 |
Date :
2017-03-16 01:13:59 |
By :
tomrambo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|