查询很简单:
Eg 1: "UPDATE threads SET hits = hits+1 WHERE id = TID"
Eg 2: "UPDATE users SET last_activity = unix_timestamp() WHERE id = UID"
`users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`last_activity` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
`threads` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`hits` int(10) unsigned NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
让我们以这个查询为例:
mysql_query("UPDATE users SET last_activity = unix_timestamp() WHERE id = UID");
没有查询,脚本需要大约 30 毫秒才能执行:
使用查询,脚本需要大约 110 毫秒来执行:
最好的问候, 杜鲁曼·埃迪
LE:生成执行时间的代码如下:
///this is placed above any code
$mtime = explode(' ',microtime());
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
.....
my game code is here
.....
$mtime = explode(' ',microtime());
echo lang('info','page_load').' '.number_format(($mtime[1] + $mtime[0]) - $tstart,4,'.','')*1000;
这就是我计算执行时间的方式,它非常准确,从来没有让我失望过。PS - 实际执行时间要低约 15 毫秒,因为我现在在 Windows 上托管它。