I'm uploading a file, to process and display a message at the end. However, the messages that drupal_set_message is set to display are displayed sometimes and don't display sometimes, even, if the processing runs successfully in the background. The reload time restriction isn't a problem as it is set to multiple minutes and the processing hardly takes 10-60 seconds on average. Is there a way to force the page to show the messages at any cost? The drupal_set_messages that I am concerned about are the last two drupal_set_messages in the code. I've even tried using drupal_set_message(t('!shell_c', array('!shell_c'=>$shell_command)), 'status'); but the issue persists where the drupal_set_message messages are shown sometimes and not shown sometimes, rather erratically.
//Before this part of the code, there is function to create Menu ($items[])
function g_p_proc_form($form, &$form_state, $values) {
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['filter'] = array (
"#type" => "fieldset",
"#title" => t("File Process <BR> "),
"#collapsible" => TRUE,
);
// without this attribute, upload may fail on submit
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['filter']['file'] = array(
// '#title' => t('File processing'),
'#type' => 'file',
'#name' => 'files[]',
'#description' => t('Select Submit to start processing the file'),
'#type' => 'file'),
'#upload_location' => 'public://',
'#attributes' => array('multiple' => 'multiple'),
);
// echo '<script type="text/javascript">Drupal.behaviors.DSU_batch_report;</script>'; //christ
if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > 'size based on my requirements') {
drupal_set_message(t(" Warning message on file size"));));
// unset($_SERVER['CONTENT_LENGTH']);
}
$form['filter']['submit_upload'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
// drupal_set_message(t("in fn"));
return $form;
}
function g_p_proc_form_submit($form, &$form_state) {
header(current page)
try{
$number_file = count($_FILES['files']['name']);
$f_name = array();
for ($i=0; $i<$number_file;$i++)
{
$file = file_save_upload($i, array('file_validate_extensions' => array('pdf PDF')), 'public://', FILE_EXISTS_REPLACE);
$f_name[] = $_FILES['files']['name'][$i]; //[]
}
}catch (Exception $error){
echo 'Exception: ', $error->getMessage(), "\n";
}
$n_f = count($f_name);
drupal_set_message(t('Number of files to process: !n_f', array('!number_f'=>$n_f)));
$fn_name = 'g_p';
$fn_call = $fn_name($f_name);
function g_p($f_name=array()){
$curr_l = getcwd();
chdir('My file processing PHP script location ');
$n_f = count($f_name);
$shell_command = shell_exec("file_processing_php_script_name.php");
//header("Location: "Current file processing module menu site"); //Commented out
drupal_set_message($shell_command); //print_r statements from the file_processing_php_script_name.php
chdir($curr_l);
}