【发布时间】:2009-12-16 14:11:26
【问题描述】:
我有一个使用 flash 和 php 开发的游戏网站。 php 代码包含 4000 行,它将作为 cron 运行。在代码内部,有一个 while 循环将无限地 运行以检查是否写入了套接字中的任何数据,并相应地调用不同的函数并将结果发送回套接字。从 flash 中,它会得到结果并显示出来。
我面临的问题是,在 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();
【问题讨论】:
-
发布您的一些代码会有所帮助;否则,它主要是一个猜谜游戏。
-
CPU 使用率?内存泄漏?是哪个?
-
在问题中发布代码会更有帮助。
标签: php