I am trying to solve the problem of processing a large csv file (12194 lines) with goods, I read the file using the parseCSV library
There is a "model code" column in the file, I need to go through each line and add a random prefix to the model code, for example: MODELCODE_PREF987 To do this, I write this code using the library methods:
<?php set_time_limit(0); require_once('parsecsv.lib.php'); $fileCSV = 'file_pred.csv'; $csv = new parseCSV(); $csv->delimiter = "\t"; $csv->parse($fileCSV); $count = count($csv->data); for($i = 0; $i<$count; $i++){ $ID = $csv->data[$i]['Код модели'] . "_" . rand(0,1000); $csv->data[$i]['Код модели'] = $ID; $csv->save(); } But the script hangs exactly on the data modification, if you just make a conclusion, then everything quickly works out. And most likely it should be so, I am only starting to understand php , and therefore my code is most likely not correct. Please give an example (addition to the comment) method of recording the file
protected function _wfile($file, $string = '', $mode = 'wb', $lock = 2) { if ($fp = fopen($file, $mode)) { flock($fp, $lock); $re = fwrite($fp, $string); $re2 = fclose($fp); if ($re != false && $re2 != false) { return true; } } return false; }