I have added some functionality to Mantis (Mantis 0.18.3) running on IIS (5 on a w2k terminal server) and PHP (php-4.3.3-Win32) .
the added functionality
- uploads an attachment
- adds a bugnote
- send an extra email containing the attachment and the bugnote
my problem is, that mantis often crashes when the code runs, after adding the attachment to the case but before or while sending the email. sometimes the browser shows weird stuff (looks like a memory dump of mantis), sometimes the cgi process simply times out and is killed by IIS after 60 secs.
I have set all relevant attachment etc. parameters in mantis and php, and it does work fine sometimes. just sometimes it does not. any idea?
Thanks, Christoph
ps:
Here is part of the code....
# #1
$t_upload_method = config_get( 'file_upload_method' ); # dunno what this is good for
if ( is_uploaded_file( $f_file['tmp_name'] ) && 0 != $f_file['size'] ) {
file_add( $f_bug_id, $f_file['tmp_name'], "(to customer) " . $f_file['name'], $f_file['type'] );
$t_nfiles++;
} else {
$f_file = null;
}
...
# send customer email
$result = email_bug_customer_status( $t_customer_name, $t_customer_email, $t_customer_replyto, $f_bug_id, $f_body, $f_file, $f_file2, $f_file3, $f_file4, $t_cc );
....
function email_bug_customer_status( $p_name, $p_email, $p_replyto, $p_bug_id, $p_message, $p_file, $p_file2, $p_file3, $p_file4, $p_cc ) {
...
# sending from whom (current mantis user)?
$mail->From = $t_sender_email;
$mail->FromName = "innovaphone [" . $t_sender_name . "]";
# reply to whom (magic malbox name/address)?
$mail->AddReplyTo($t_replyto_email, $t_replyto_name);
# add attachments
if ($p_file != null) $mail->AddAttachment($p_file['tmp_name'], $p_file['name']);
if ($p_file2 != null) $mail->AddAttachment($p_file2['tmp_name'], $p_file2['name']);
if ($p_file3 != null) $mail->AddAttachment($p_file3['tmp_name'], $p_file3['name']);
if ($p_file4 != null) $mail->AddAttachment($p_file4['tmp_name'], $p_file4['name']);
if ( ! is_blank( $g_smtp_username ) ) { # Use SMTP Authentication
$mail->SMTPAuth = true;
$mail->Username = $g_smtp_username;
$mail->Password = $g_smtp_password;
}
# add to the Recipient list (name/address bug was initiated from)?
$mail->AddAddress($p_email, $p_name);
# add to the CC list
$t_cc_list = split(',', $p_cc);
while(list(, $t_cc) = each($t_cc_list)) {
if ( !is_blank( $t_cc ) ) {
# $mail->AddCC( $t_cc);
# $mail->AddBCC( $t_cc);
$mail->AddAddress( $t_cc );
}
}
# add to the BCC list
$t_bcc_list = split(',', $t_bcc);
while(list(, $t_bcc) = each($t_bcc_list)) {
if ( !is_blank( $t_bcc ) ) {
$mail->AddBCC( $t_bcc);
# $mail->AddAddress( $t_bcc );
}
}
$mail->Subject = $t_subject;
$t_message = make_lf_crlf( "\n" . $t_message );
# $t_message .= "\n\n------ Incident Status ------\n\n";
# $t_message .= email_build_bug_message( $p_bug_id, $t_message, $t_category );
# $t_message .= email_build_history_message( $p_bug_id );
$t_message .= "\n\n---------------------\n";
$t_message .= "This email has been sent to you by innovaphone's ticket system.\n" ;
$t_message .= "For further communication regarding this case, reply to this email.\n";
$t_message .= "If you need to call, be sure to note the ticket id " . $p_bug_id . "\n";
$mail->Body = "\n" . $t_message;
$mail->AddCustomHeader( "Keywords: " . $p_bug_id . ", " . "innovaphone, presales" );
if( !$mail->Send() ) {
PRINT "PROBLEMS SENDING MAIL TO: $t_recipient<br />";
PRINT 'Mailer Error: '.$mail->ErrorInfo.'<br />';
exit;
}
sporadic problems with sending email and/or adding attachmen
Moderators: Developer, Contributor
I have narrowed it down a bit... still help required
the problem is in core/file_api.php. the upload mode is DATABASE. I have put some debugs and the php.exe hangs while tries to add the file as an attachment to the database ("add file: inserting..." is the last thing I see).
This happens with very large attachments or with binary attachments.
Is this a known problem?
:-) Christoph
excerpt from core/file_api.php
case DATABASE:
print "method DATABASE: prepare string size=" . $t_file_size . "\n";
$c_content = db_prepare_string( fread ( fopen( $p_tmp_file, 'rb' ), $t_file_size ) );
print "prepared string \n";
break;
default:
trigger_error( ERROR_GENERIC, ERROR );
}
$query = "INSERT INTO $t_bug_file_table
(id, bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)
VALUES
(null, $c_bug_id, '', '', '$c_file_path$c_new_file_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', NOW(), '$c_content')";
print "\nadd file: inserting...\n";
db_query( $query );
print "\nadd file: inserted...\n";
This happens with very large attachments or with binary attachments.
Is this a known problem?
:-) Christoph
excerpt from core/file_api.php
case DATABASE:
print "method DATABASE: prepare string size=" . $t_file_size . "\n";
$c_content = db_prepare_string( fread ( fopen( $p_tmp_file, 'rb' ), $t_file_size ) );
print "prepared string \n";
break;
default:
trigger_error( ERROR_GENERIC, ERROR );
}
$query = "INSERT INTO $t_bug_file_table
(id, bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)
VALUES
(null, $c_bug_id, '', '', '$c_file_path$c_new_file_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', NOW(), '$c_content')";
print "\nadd file: inserting...\n";
db_query( $query );
print "\nadd file: inserted...\n";