ctsit / export_large_projects

A REDCap module for exporting very large projects
1 stars 4 forks source link

Module throws a fatal error when the execution time is exceeded #10

Open rajputd opened 6 years ago

rajputd commented 6 years ago

When processing each batch export.php will throw a fatal timeout error if processing the batch takes too long. image

The offending code is lines 62-80:

foreach ($batches as $count => $batch) {
    set_time_limit($_GET['max_execution_time_per_batch']);

    try {
        $records = REDCap::getData('csv', $batch);

        // Trim the header on all but the first row of the first batch.
        if ($count) {
            $first_lb = strpos($records, "\n");
            if ($first_lb !== false) {
                $records = substr($records, $first_lb + 1);
            }
        }

        fwrite($fh, $records);
    }
    catch (Exception $e) {
        $module->callJsCallback('displayErrorMsg');
    }

The set_time_limit method throws the fatal error. This type of error cannot by caught by try, catch blocks.

To recreate this issue insert a while(true) statement inside the foreach loop and set the max execution time (which is configured in the module's settings) to something small like 2 seconds.