Importing large CSV files using cron jobs in Laravel
<p>I'm using <strong>Laravel 8</strong> and I want to <strong>update billions of product prices</strong>. I added this <strong>code and it worked fine</strong> but it was <strong>not efficient</strong> and it increased the <strong>load on the server</strong> . </p>
<pre class="brush:php;toolbar:false;">try {
$priceCsvs = PriceCsv::whereStatus(PriceCsv::PENDING)->get();
foreach ($priceCsvs as $price) {
dump($price->name." is started");
$csvData = fopen($price->file_url, 'r');
$firstline = true;
while (($data = fgetcsv($csvData, 555, ',')) !== false) {
if (!$firstline && !empty($data)) {
dump($data);
}
$firstline = false;
}
fclose($csvData);
dump($price->name." is End");
}
} catch (\Exception $ex) {
dump($ex->getMessage());
}</pre>
<p><em><strong>The point is: </strong></em>Is there a way to get the input from a <strong>CSV file</strong> or any other file<strong> Add sleep after 1000 times</strong>What works. </p>