Php showing 97% of CPU usage
<p>I have a game site developed using flash and php. The php code contains 4000 lines and it will run as a cron. Inside the code, there is one while loop which will run <strong>infinitely</strong> for checking any data is written in the socket and call different functions accordingly and will send the results back to the sockets.  From flash, it will get the results and will be displayed. </p>

<p>The problem Im facing is, somewhere from the php code, it is leaking memory. Since it is very big, I can not find out from where it is happening. Moreover it can be run only as a cron. Is there any tool to find out the memory leakage ? I have heard about xdebug but I didnt use. Any other ?</p>

<p>check.php (as cron)</p>

<pre><code>$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";}
</code></pre>

<p>server.php (only some part)</p>

<pre><code>class gameserver {
var $server_running = true;
function gameserver() {
 global $cfg, $db;

 $this-&gt;max_connections = $cfg["server"]["max-connections"];

 $this-&gt;start_socket();

 echo "Gameserver initialized\n";
 while ($this-&gt;server_running) {
  $read = $this-&gt;get_socket_list();
  $temp = socket_select($read, $null, $null, 0, 15);
  if (!empty($read)) {
   $this-&gt;read_sockets($read);
  }
  $db-&gt;reconnection();
  $this-&gt;update_DB_records();
  $this-&gt;check_games_progress();

  if ($this-&gt;soft_shutdown &amp;&amp; $this-&gt;active_games == 0) {
   $this-&gt;server_running = false;
   echo "soft shutdown complete\n";
  }
 }

 $this-&gt;stop_socket();

 echo "Server shut down\n";
}}        $server = new gameserver();
</code></pre>
