【发布时间】:2013-12-08 22:48:46
【问题描述】:
我找到了一个使用 php 长轮询的脚本。 它使用以下代码查看文本文件是否更改并返回内容。 这是由浏览器接收的。
如何更改它以读取表格并查看是否有新事件?
$filename= dirname(__FILE__)."/data.txt";
$lastmodif = isset( $_GET['timestamp'])? $_GET['timestamp']: 0 ;
$currentmodif=filemtime($filename);
while ($currentmodif <= $lastmodif) {
usleep(10000);
clearstatcache();
$currentmodif =filemtime($filename);
}
$response = array();
$response['msg'] =Date("h:i:s")." ".file_get_contents($filename);
$response['timestamp']= $currentmodif;
echo json_encode($response);
我有一张桌子,里面有“帖子”。 post_id,内容,user_id,posted_time
我怎么知道有没有新帖子?
【问题讨论】:
标签: php jquery mysql ajax long-polling