您必须将 php 脚本设置为每隔 x 分钟左右运行一次,而不是回显结果,而是根据当前播放的歌曲检查最近的数据库条目,如果不同,则添加新记录.
首先,一些SQL来建立一个新表:
CREATE TABLE SongList (
ID int primary key auto_increment not null,
Song char(255) not null,
PlayTime Datetime not null
);
然后,修改您的 PHP 脚本以在数据库中插入记录而不是回显到屏幕:
<?php
$song = get_song(); //not sure how you're doing that
$sql = "SELECT Song FROM SongList ORDER BY PlayTime DESC LIMIT 1";
list($prevSong) = mysql_fetch_row(mysql_query($sql));
if ($song !== $prevSong) {
$sql = "INSERT INTO SongList (Song, PlayTime) VALUES ('$song', NOW())";
mysql_query($sql);
}
?>
设置计划任务或 cron 作业以每分钟运行 php -f z1035.php。
要查看完整的歌曲列表,请创建一个新的 php 文件 station_history.php
<html>
<body>
<pre>
<?php
$sql = "SELECT Song, PlayTime FROM SongList LIMIT 20"; // Just the last 20 songs
$result = mysql_query($sql);
while(list($song, $playtime) = mysql_fetch_row($result)) {
echo "[$playtime] $song\n";
}
?>
</pre>
</body>
</html>