|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-12-06 19:42 UTC] ctocopok at fond-darina dot ru
Trying to make a mailling list script on a php encountered a strange PHP behaviour.
config: Win2K, Apache 1.3.20 (Win32), PHP 4.2.3 (just downloaded from php.net)
Script:
<?
//diff set-up steps skipped
$mbox = imap_open ("{".$server.":".$port."/pop3}INBOX", "$uname", "$passw");
//following lines work on the results
?>
first I worked with my local pop3 server (WinRoute built-in). everything went fine, but then suddenly I got no changes in the output after I was changing my script.
I changed the server to another one (mail.ru) and continued working. 30 minutes of happy working until that server went "dead" too.
I changed the pop3 server the third time. It worked, but finally began bugging too!
I started searching the point where the bug comes from.
got the following from apache error.log file (debug level of logging):
--------
abnormal program termination
[Sat Dec 07 04:34:06 2002] [info] master_main: Child processed exited (due to MaxRequestsPerChild?). Restarting the child process.
[Sat Dec 07 04:34:06 2002] [info] Parent: Created child process 2100
[Sat Dec 07 04:34:06 2002] [info] Parent: Duplicating socket 428 and sending it to child process 2100
[Sat Dec 07 04:34:07 2002] [info] BytesRead = 372 WSAProtocolInfo = 2006620
--------
Phperror.log contains nothing about the problem.
Commenting the "$mbox = imap_open()" makes script working as usual.
starting the script with "php -f script.php >1.html" make PHP print "abnormal program termination" and quit.
1.html file remains empty.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 00:00:02 2025 UTC |
<? $port="110"; $server="localhost"; $uname="test"; $passw="1234"; phpinfo(); //to start the output $mbox = imap_open ("{".$server.":".$port."/pop3}INBOX", "$uname", "$passw"); echo imap_last_error()."<br>"; $totmsg=imap_num_msg($mbox); //still works if ($totmsg>0) echo "some messages found<br>"; $headers=imap_search($mbox, "FROM @", 0);//fails $headers=imap_headers($mbox);//fails //any of above would 'crash'. if (is_array($headers))echo "Total messages found: ".count($headers)."/$totmsg<br>"; ?>Yes. The crash happens with any e-mail. Does not depend on the e-mail encoding or charset or whatever. It happens, I suppose, in imap_fetchbody, the function I use to get the raw e-mail headers (the used to fall into section #0 of the e-mail body, no matter if mail had any parts). As to the script - the PHP-file I use to test the bug is constantly growing as I add more debug output to find the exact point where the 'crash' occurs. As to the servers - there are many if them. WinRoute's internal pop3 server (my local), and some other servers on the net (mail.ru, goals.ru, valuehost.ru) - these are the servers I tried. Local testing reports that the mails get transferred to PHP. Even twice (so if the mailbox occupies 100Kbytes of mail for user, the total session traffic would be 200K). Here is the script I use now (still crashiong with fetchbody): <? ini_set("display_startup_errors","1"); $f=fopen('log','w+'); $enc[0]="7BIT"; $enc[]="8BIT"; $enc[]="BINARY"; $enc[]="BASE64"; $enc[]="QUOTED-PRINTABLE"; $enc[]="OTHER"; $port="110"; $server="localhost"; $uname="test"; $passw="1234"; //phpinfo(); function desc_arr($arr,$prefix) { global $f; foreach($arr as $key=>$value) { echo "$prefix [$key] = $value <br>"; fputs($f, "$prefix [$key] = $value <br>\n"); if (is_array($value))desc_arr($value, "$prefix [$key]"); if (is_object($value))desc_obj($value,"$prefix [$key]"); } } function desc_obj($obj, $prefix) { global $f; foreach($obj as $key=>$value) { echo "$prefix -> $key = $value <br>"; fputs($f, "$prefix -> $key = $value <br>\n"); if (is_array($value))desc_arr($value, "$prefix -> $key"); if (is_object($value))desc_obj($value,"$prefix -> $key"); } } fputs($f, "connecting to $server<br>\n"); echo "connecting to $server<br>"; $mbox = imap_open ("{".$server.":".$port."/pop3}INBOX", "$uname", "$passw"); echo imap_last_error()."<br>"; fputs($f,imap_last_error()."<br>\n"); echo "Retrieving messages...<br>"; fputs($f, "Retrieving messages...<br>"); $totmsg=imap_num_msg($mbox); $check = imap_mailboxmsginfo($mbox); if($check) { print "Date: " . $check->Date ."<br>\n" ; fputs($f, "Date: " . $check->Date ."<br>\n" ); print "Driver: " . $check->Driver ."<br>\n" ; print "Mailbox: " . $check->Mailbox ."<br>\n" ; print "Messages: ". $check->Nmsgs ."<br>\n" ; print "Recent: " . $check->Recent ."<br>\n" ; print "Unread: " . $check->Unread ."<br>\n" ; print "Deleted: " . $check->Deleted ."<br>\n" ; print "Size: " . $check->Size ."<br>\n" ; } else { print "imap_check() failed: ".imap_last_error(). "<br>\n"; fputs($f,"imap_check() failed: ".imap_last_error(). "<br>\n"); } if ($totmsg>0) {echo "some messages found<br>";fputs($f,"some messages found<br>\n");} if ($totmsg>0) echo "some messages found<br>"; if ($totmsg>0) echo "some messages found line 3<br>"; $headers=imap_search($mbox, "FROM @", 0);// if (is_array($headers)) {echo "Total messages found: ".count($headers)."/$totmsg<br>"; fputs($f,"Total messages found: ".count($headers)."/$totmsg<br>\n"); desc_arr($headers, "headers"); } while (list ($key,$val) = each ($headers)) { unset($hdr); $hdr=imap_headerinfo($mbox, ($val)); desc_obj($hdr, "HDR:"); echo "Plaintext is:<br><code>".nl2br(imap_body($mbox, ($val)))."</code><br>"; fputs($f,"Plaintext is:<br><code>".nl2br(imap_body($mbox, ($val)))."</code><br>\n"); echo "<hr>...Fetching structure<br>"; fputs($f,"<hr>...Fetching structure<br>\n"); unset($struc); $struc=imap_fetchstructure($mbox,($val)); echo "struc assigned<br>"; fputs($f, "struc assigned\n"); desc_obj($struc, "structure"); if (isset($struc->parts)) //There are some parts { echo "<b>there are ".count($struc->parts)." parts in the message</b><br>"; fputs($f, "<b>there are ".count($struc->parts)." parts in the message</b><br>\n"); foreach($struc->parts as $num=>$part) { echo "foreach struc-parts started<br>"; fputs($f, "foreach struc-parts started<br>\n"); echo "Part $num<br>"; fputs ($f, "Part $num<br>\n"); if ($part->subtype=='PLAIN') { echo "part subtype=PLAIN<br>"; fputs($f, "part subtype=PLAIN<br>\n"); $msg=imap_fetchbody($mbox,$key, $num); // ***CRASH *** // echo "The text is ".nl2br($msg)." <br>"; fputs($f,"The text is ".nl2br($msg)." <br>\n"); } $filename=""; if ($part->ifdisposition==1) { echo "Part $num has disposition $part->disposition<br>"; fputs($f, "Part $num has disposition $part->disposition<br>\n"); if ($part->ifdparameters==1) { echo "there are Dparameters for it<br>"; fputs($f, "there are Dparameters for it<br>\n"); foreach ($part->dparameters as $dpname=>$dpval) { if ($dpval->attribute=="FILENAME"){ echo "Filename is ".($filename=$dpval->value)."<br>"; fputs($f, "Filename is ".($filename=$dpval->value)."<br>\n"); } } } } } } else { echo "<b>Seems this message has the only part</b>:<br><code>".imap_body($mbox, ($val))."</code><br>"; fputs($f, "<b>Seems this message has the only part</b>:<br><code>".imap_body($mbox, ($val))."</code><br>\n"); } echo "<hr>Body:<br>".imap_body($mbox, ($val))."<br><hr>"; fputs($f, "<hr>Body:<br>".imap_body($mbox, ($val))."<br><hr>\n"); echo "Part0 if exists:<br>"; fputs($f, "Part0 if exists:<br>\n"); echo "Key: $key, val: $val<br>"; $alerts=imap_alerts(); if(is_array($alerts))echo "Here we have alerts:<br>".desc_arr($alerts," ALRT:"); echo "Alerts:".$alerts; echo "lalala".imap_fetchheader($mbox,$key+1); // fputs($f, "\nlalala".imap_fetchbody($mbox,$key, 0)); //commented out because of crash } imap_close($mbox); ?>