prepare("INSERT INTO submissions (name) VALUES (:name)"); $importedCount = 0; $rowCount = 0; while (($data = fgetcsv($handle)) !== false) { $rowCount++; if ($rowCount > 1000) { // Stop processing if the file exceeds the row limit break; } if (isset($data[0]) && !empty(trim($data[0]))) { try { $stmt->execute(['name' => trim($data[0])]); $importedCount++; } catch (PDOException $e) { // You might want to log this error instead of ignoring it // error_log("CSV Import Error: " . $e->getMessage()); continue; // Continue to the next row } } } fclose($handle); // Trigger the background worker now that new submissions are in if ($importedCount > 0) { shell_exec('php /home/ubuntu/executor/workspace/worker.php > /dev/null 2>&1 &'); } if ($rowCount > 1000) { header('Location: analyst_dashboard.php?error=' . urlencode('CSV file exceeds the 1000-row limit. Only the first 1000 rows were processed.') . '&success=' . $importedCount); } else { header('Location: analyst_dashboard.php?success=' . $importedCount); } exit;