【发布时间】:2022-02-11 09:02:46
【问题描述】:
我正在尝试计算玩家在服务器上花费的总时间。
我每 5 分钟有一个 PHP cron 作业,它将从服务器查询详细信息 https://developer.valvesoftware.com/wiki/Server_queries
array (
'id' => '1',
'name' => 'Player',
'score' => '3',
'time' => '1234',
),
array (
'id' => '2',
'name' => 'Player 2',
'score' => '12',
'time' => '2453',
) + other 100k players.
// The 'time' is starting from 0 seconds when the player join the server, if she leave and then join again the time is starting from 0 seconds
只需将实时数据从 PHP 查询添加到数据库
| id | name | last_score | total_score | last_time | total_time |
| -- | -------- | ---------- | ----------- | --------- | ---------- |
| 1 | Player | 3 | 0 | 1234 | 0 |
| 2 | Player 2 | 12 | 0 | 2453 | 0 |
我不是玩家在线的服务器的所有者,因此我无法在玩家离开时立即登录。
我正在尝试做这样的事情https://www.gametracker.com/server_info/109.120.135.78:2302/top_players/
【问题讨论】:
-
创建一个新表来按玩家 ID 存储开始和停止时间,然后您的 CRON 作业只需从中计算总数。
-
感谢您的评论,我现在添加了一个更详细的示例。
标签: php date time calculation