ID: 20033
Updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
-Status: Open
+Status: Feedback
Bug Type: Sockets related
Operating System: Red Hat 7.3
PHP Version: 4CVS-2002-10-22
New Comment:
Does PHP eat a lot of CPU when it hangs?
Are you capable of running it under gdb and obtaining a backtrace?
make sure you are running an --enable-debug build of PHP.
gdb ./sapi/cli/php
run nameofyourscript.php
[hit CTRL-C when it hangs]
bt full
This would be ideal, because then we would know 100%
what was going on.
In light of your comments about shutdown, what happens if you comment
out the fclose() line?
Also, what are your ini settings for output buffer related options?
(and does changing those affect the problem?)
Previous Comments:
------------------------------------------------------------------------
[2002-10-23 12:13:57] [EMAIL PROTECTED]
I added requested fflush on $logfile after each fputs. It still
indicates that it is dying on the "echo". I.e., logfile shows "Echoing
line" but never reports "Sent."
Additional important correction: I'm not sure whether behavior has
changed or if I was just wrong before, but when the problem presents
itself the script IS shutting down and the TCP/IP connection IS
disconnected. In fact, it does so cleanly. It executes my registered
shutdown function. In that function I had it write to the logfile and
it shows that after the last "Echoing" line it DOES go through the
shutdown function. Connection_status() within the shutdown function
reports "1" (aborted), but the client side definitely didn't request
the abort.
I have also refined the loop so that the possible infinite loop
situation is handled. This is a welcome improvement to my code to
handle an "impossible" situation (impossible because it is constrained
elsewhere by logic) but it didn't have any effect on the current
problem.
------------------------------------------------------------------------
[2002-10-23 06:26:33] [EMAIL PROTECTED]
while(ftell($mailfile) < $EndOfMessagePos)
This line has the potential to cause a indefinete loop and there's no
escape code in the loop, which breaks it.
ftell will return FALSE if an error occurs, which in numerical
comparison resolves to 0.
Can you change that to:
while(ftell($mailfile) and ftell($mailfile) < $EndOfMessagePos)
------------------------------------------------------------------------
[2002-10-23 03:54:00] [EMAIL PROTECTED]
It's more likely to be a problem with fgets; could you
try fflush($logfile) ing after the fputs lines, just to make sure that
they're not waiting in the buffer.
Also, when php hangs, is it using a lot of CPU?
------------------------------------------------------------------------
[2002-10-22 17:42:38] [EMAIL PROTECTED]
Code I am using is:
while(ftell($mailfile) < $EndOfMessagePos)
{
fputs($logfile, "Getting line\n");
$line = fgets($mailfile, 4096);
fputs($logfile, "Echoing line\n");
echo "$line\r\n";
$fst += strlen($line);
fputs($logfile, "Sent $fst: $line\n");
}
echo ".\r\n";
fputs($logfile, "Sent: CRLF\n");
fclose($logfile);
End of log file returns:
--START--
Getting line
Echoing line
Sent 11060: (unimportant email content)
Getting line
Echoing line
Sent 11147: (unimportant email content)
Getting line
Echoing line
--END--
Thus it appears to be hanging on the "echo" line.
Again, this problem only presents itself when the script is running as
a full server on a "clean" connection. If the same exact test is run
connecting via the telnet command to port 110 or by running the script
from the command-line there is no problem. It is my guess that the
telnet command introduces some kind of flow control that is not present
when I open a "real" POP3 connection to the same port.
------------------------------------------------------------------------
[2002-10-22 16:57:05] [EMAIL PROTECTED]
Can you isolate the line of code that causes the hang?
Use printf to output a note before each function you suspect of causing
the problem; the last line output
by the script will tell you which one has hung.
We need to narrow it down to either sockets (as in ext/socket), or
streams (fgets, fread, fwrite etc.),
or output buffer -- three unrelated areas.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/20033
--
Edit this bug report at http://bugs.php.net/?id=20033&edit=1