Może nie wrzucaj po kolei wszystkiego, jakieś małe dane, tylko od razu większą część bądź całość.
Wykonaj konkatenację ".=" i dopiero append'uj do pliku.
Wydaje mi się, że problem polega na zbyt długim czasie oczekiwania na odpowiedź, żeby to zmienić musisz zmienić ustawienia serwera np. Apache z poziomu PHP lub Serwera. Poszukaj w ustawieniach konfiguracyjnych związanym z czasem response, itp. Pliki np. php.ini i tego typu.
php.net php.net php.net
Wyjaśnij może w jaki sposób dane ściągasz metodą POST, Ajax'em, czy czymś innym.
You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php.ini directive as well as through the corresponding php_value ignore_user_abort Apache httpd.conf directive or with the ignore_user_abort() function. If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate. The one exception is if you have registered a shutdown function using register_shutdown_function(). With a shutdown function, when the remote user hits his STOP button, the next time your script tries to output something PHP will detect that the connection has been aborted and the shutdown function is called. This shutdown function will also get called at the end of your script terminating normally, so to do something different in case of a client disconnect you can use the connection_aborted() function. This function will return TRUE if the connection was aborted.
php.net
Ustaw w php.ini właściwość ignore_user_abort na ;ignore_user_abort. Po prostu wstaw tam średnik (wykomentuj) tę linię. Cytat mówi, że można tym kierować za pomocą httpd.conf lub z poziomu kodu PHP.
php.net php.net php.net php.net php.net
w pętli wykonuja się dwa zapytania
delete oraz insert, sytuacja jest taka że muszą się wykonywać pokolei czyli każde zapytania na każdym z 300 elementów tablicy
Pakietami ślij dane do pliku, nie po kolei jeśli możesz, ponieważ za długo to trwa, zgodnie z tym co opisujesz. Jest instrukcja mysqli::multi_query, która wykonuje grupowo zapytania SQL, żeby nie były wykonywane jedna po drugiej.