CSV import over Ajax fails when over 2000 requests, causing server failure

413 views Asked by At

I'm trying to import CSV data to MySQL over Ajax for an email program. Everything works good for 2000 Ajax requests but then the browser/server gives failures.

I tried several approaches, but I can't find a solution.

My code:

<?php
$zeilen = file('uploads/'.$dateipfad);

$gesamtzeilen = count($zeilen);

?>
<script type="text/javascript">
datenzeilen = []; <? php foreach($zeilen as $zeile) { ?>
        datenzeilen.push( <? php echo json_encode($zeile); ?> ); <? php
} ?>
</script>
<script type="text/javascript">
for (var i = 0; i < datenzeilen.length; i++) {
    var aktuelledaten = datenzeilen[i];
    $.ajax({
        type: "POST",
        url: "import.php",
        data: {
            trennzeichen: <? php echo '"'.$trennzeichen.
            '"'; ?> ,
            empfaengerliste: <? php echo '"'.$empfaengerliste.
            '"'; ?> ,
            aktuelle_daten: aktuelledaten,
            csvfelder: <? php echo '"'.implode(",", $csv_names).
            '"'; ?>
        },
        success: function (strResponse) {
            var gesamt = <? php echo $gesamtzeilen; ?> ;
            document.getElementById("gesamtanzahl").innerHTML = gesamt;
        }
    });
}
</script>
0

There are 0 answers