ID: 10092
User Update by: [EMAIL PROTECTED]
Old-Status: Feedback
Status: Open
Bug Type: Sockets related
Description: Socket fgets memory and CPU usage problem

The code snippet:
This is a PHP POP3 Socket Test that demonstrates a Windows PHP CGI bug which consumes 
the transfered data thru the socket 
and never releases them. Each round of the for cycle below gets slower and slower and 
never finishes the end.
To test it edit the POP3 server variables below. Make sure there's only one 500K 
message in the POP3 mailbox.
Then run the test. Currently the PHP gives up in the 11th cycle. On windows 9x the PHP 
stops running. On windows
NT/2000 the PHP goes crazy, consumes 100% CPU and never finishes.

Please, contact me:
Jakub Klos

PHP POP3 Socket Test<BR><BR>

  $server = "localhost";
  $port = 110;
  $user = "user";
  $pass = "pass";
  $round = 20;
  // connect to the POP3 server and read the response
        $socket = fsockopen($server, $port);
        $line = fgets($socket, 1024);
  // USER and PASS commands
        fputs($socket, "USER $user\r\n");
        $line = fgets($socket, 1024);
        fputs($socket, "PASS $pass\r\n");
        $line = fgets($socket, 1024);
  $length = 0;
  for ($i = 1; $i < $round + 1; $i++)
    // RETR command to receive the message
        fputs($socket, "RETR 1\r\n");
    $line = fgets($socket, 1024);
    if ($line[0] == "-") break;
    while (($line = fgets($socket, 1024)) <> ".\r\n")
      if (!($line)) break;
      $length += strlen($line);

    echo "Round $i/$round, Transfered $length<BR>";
  echo "Total bytes received: $length";

Previous Comments:

[2001-03-31 17:18:02] [EMAIL PROTECTED]
Please add a self containing short script into this report
which can be used to reproduce this problem.



[2001-03-31 09:56:39] [EMAIL PROTECTED]
When using the fgets function for large data transmission the data transmitted are 
never freed from memory. When using fgets with files it works fine. The PHP CGI module 
starts to utilize the CPU to 100% and never ends, stops processing and doesn't exit 
the fgets function after few read cycles. This happens only on Windows PHP CGI. We 
tested Apache and that worked fine. Even the previous version of PHP did that. Large 
data I'm talking about is 8MB and above. 


Full Bug description available at:

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to