I have this script that is supposed to read a big csv file and insert the contents into database(mysql). I am running the script from terminal ie php index.php however after some time the script prints out Terminated and stops running without any reasonable error.
I have added all these to the script but still can't get it to finish exacution: set_time_limit(0);
ignore_user_abort() ;
ini_set('memory_limit','5120M');
Below is a snipet of the code.NB I have just picked a small bit of it.
<?php
set_time_limit(0);
ignore_user_abort() ;
ini_set('memory_limit','5120M');
echo ini_get("memory_limit")."
";
$conn = new mysqli("dbase1", "apps", "t3ck", "transactional");
$files = array("/home/username/mycsv.csv");
foreach($files as $file){
echo "----------------------------------------------------------------------------------$file--------------------------------------------
";
$rows = array_map('str_getcsv', file($file));
$csv = array();
$array = explode(".",$file);
$name = $array[0];
//$service = getserviceId($name);
foreach ($rows as $row) {
$conn->query("INSERT INTO transactions (foreign_key, model, created, modified) VALUES (NULL, NULL, now(), now());");
$count = $conn->insert_id;
echo "TRX id: $count
";
$no= $row[0];
$net = "FDO";
$query = "insert ignore into text_gf services_id,no,net,sub_date,transactions_id,created,last_delivery_date) VALUES(118,$no,$net,now(),$count,now(),now())";
$res =$conn->query($query);
if($res) {
echo "$msisdn saved
";
} else {
print_r($conn->error);
die();
}
}
unlink($file);
}