我有一个使用flash和php开发的游戏网站。该PHP代码包含4000行,它将作为一个cron运行。在代码中,有一个while循环,它将无限地运行用于检查任何数据写入套接字并相应地调用不同的函数,并将结果发送回套接字。从闪光灯,它会得到结果,并将显示。Php显示CPU使用率的97%
我面对的问题是,从PHP代码的某个地方,它正在泄漏内存。由于它非常大,我无法从中发现它。而且它只能作为cron运行。有没有什么工具可以找出内存泄漏?我听说过xdebug,但我没有使用。任何其他 ?
check.php(如的cron)
$sock = fsockopen(IP_ADDRESS, PORT, $sock_error_code, $sock_error_string, 10); if (!$sock){
$message = "Server was down, restarting...\n\n";
$last_line = system("php -q gameserver/server.php", $retval);} else {
$message = "Server is up...";
$message .= $sock_error_string." (".$sock_error_code.")\n\n";}
server.php(仅限某些部分)
class gameserver {
var $server_running = true;
function gameserver() {
global $cfg, $db;
$this->max_connections = $cfg["server"]["max-connections"];
$this->start_socket();
echo "Gameserver initialized\n";
while ($this->server_running) {
$read = $this->get_socket_list();
$temp = socket_select($read, $null, $null, 0, 15);
if (!empty($read)) {
$this->read_sockets($read);
}
$db->reconnection();
$this->update_DB_records();
$this->check_games_progress();
if ($this->soft_shutdown && $this->active_games == 0) {
$this->server_running = false;
echo "soft shutdown complete\n";
}
}
$this->stop_socket();
echo "Server shut down\n";
}} $server = new gameserver();
发布你的一些代码会有帮助;否则,它主要是一个猜谜游戏。 – 2009-12-16 14:24:25
CPU使用率?内存泄漏?这是什么? – 2009-12-16 14:25:32
在问题中发布代码会稍微有帮助。 – 2009-12-16 15:08:08