Maybe that is the error:
Content-type: text/html; charset=UTF-8
Do you use the same charset on your remote machine as on local? Should not matter but you never know.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
This command is working in localhost(Windos 10): php artisan import:products then I uploaded to live centos server and go into my project root folder(client) and execute this command it works and after some time it shows me error memory limit exceeded then I edit php ini file from cPanel and increase memory limit to 128M after that I run this command again and it display nothing even I can't clear cache, config
php artisan cache:clear
php artisan config:clear
php artisan config:cache
After some searching, I run the command with sudo and it shows 500 Internal server error but no file pointed.
here is some output of my cli:
[root@cpanel client]# php artisan import:products
[root@cpanel client]# sudo php artisan import:products
Status: 500 Internal Server Error
Content-type: text/html; charset=UTF-8
[root@cpanel client]# php artisan cache:clear
[root@cpanel client]# php artisan config:clear
[root@cpanel client]# php artisan config:cache
[root@cpanel client]#
Please help! I have no idea what's going on, you can see all the above commands are not working.
Server log error
[30-Aug-2018 08:45:01 UTC] PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 36864 bytes) in /home/exmpale/public_html/client/vendor/composer/autoload_static.php on line 4225
Here is my server detail
CentOS Linux release 7.5.1804 (Core)
PHP 7.2.9
laravel/framework v5.6.35
Here is code:
<?php
namespace App\Console\CommandsImportData;
use Illuminate\Console\Command;
use DB;
use Mail;
use Storage;
/*
* How to run this command?
* Open a console window in project root folder
* php artisan import:products
*/
class ImportProducts extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:products';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Import bigbuy products';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$totalInsert = $totalUpdated = 0;
$languagesArr = array(
'en',
'da',
'fr',
'de',
'it',
'nl',
'no',
'pl',
'ru',
'es',
'sv',
);
$countryIdsArr = array(
'en'=>229,
'da'=>56,
'fr'=>72,
'de'=>80,
'it'=>106,
'nl'=>155,
'no'=>165,
'pl'=>176,
'ru'=>182,
'es'=>202,
'sv'=>210,
);
foreach($languagesArr as $lang){
if($lang=='fr'){
$filePathArr[$lang] = [
"csv-gnral-produits-2399-$lang.csv",
"csv-gnral-produits-2403-$lang.csv",
"csv-gnral-produits-2491-$lang.csv",
"csv-gnral-produits-2501-$lang.csv",
"csv-gnral-produits-2507-$lang.csv",
"csv-gnral-produits-2570-$lang.csv",
"csv-gnral-produits-2571-$lang.csv",
"csv-gnral-produits-2609-$lang.csv",
"csv-gnral-produits-2662-$lang.csv",
"csv-gnral-produits-2672-$lang.csv",
"csv-gnral-produits-2678-$lang.csv",
"csv-gnral-produits-3046-$lang.csv",
];
}
elseif($lang=='es'){
$filePathArr[$lang] = [
"csv-de-productos-general-2399-$lang.csv",
"csv-de-productos-general-2403-$lang.csv",
"csv-de-productos-general-2491-$lang.csv",
"csv-de-productos-general-2501-$lang.csv",
"csv-de-productos-general-2507-$lang.csv",
"csv-de-productos-general-2570-$lang.csv",
"csv-de-productos-general-2571-$lang.csv",
"csv-de-productos-general-2609-$lang.csv",
"csv-de-productos-general-2662-$lang.csv",
"csv-de-productos-general-2672-$lang.csv",
"csv-de-productos-general-2678-$lang.csv",
"csv-de-productos-general-3046-$lang.csv",
];
}
else{
$filePathArr[$lang] = [
"general-products-csv-2399-$lang.csv",
"general-products-csv-2403-$lang.csv",
"general-products-csv-2491-$lang.csv",
"general-products-csv-2501-$lang.csv",
"general-products-csv-2507-$lang.csv",
"general-products-csv-2570-$lang.csv",
"general-products-csv-2571-$lang.csv",
"general-products-csv-2609-$lang.csv",
"general-products-csv-2662-$lang.csv",
"general-products-csv-2672-$lang.csv",
"general-products-csv-2678-$lang.csv",
"general-products-csv-3046-$lang.csv",
];
}
}
#Import products
foreach($filePathArr as $lang=>$filesArr){
foreach($filesArr as $key=>$fileName){
echo "Importing file==> $fileName \n";
$filePath = storage_path('app') . "/public/bigbuy/$fileName";
if (!file_exists($filePath) || !is_readable($filePath)){
echo $fileName."\n";
die("File not exists or can not readable...");
//continue;
}
$delimiter = ';';
$header = null;
$data = array();
if (($handle = fopen($filePath, 'r')) !== false){
while (($row = fgetcsv($handle, 100000, $delimiter)) !== false){
#First line consider head and save into header array
if (!$header){
#This will clean each string from hidden characters.
$row = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $row);
$header = $row;
}else{
$data[] = array_combine($header, $row);
}
}
}
//$jsonEncodedData = json_encode($data);
//echo $jsonEncodedData;exit;
foreach($data as $key=>$row){
//echo "inserting data";
try{
$slug = str_slug($row['NAME']);
if(empty($slug)){
//echo "slug is empty";
continue;
}
#Insert in shop products for en lang
if($lang == 'en'){
//echo "Langue is en";
$exist = DB::table('shop_products')
->where('slug',$slug)->count();
if(!$exist){
$catsArr = explode(',',$row['CATEGORY']);
$parentCatId = $catsArr[0];
try{
//echo "inserting query";
DB::table('shop_products')->insert([
'title'=>$row['NAME'],
'slug'=>$slug,
'description'=>$row['DESCRIPTION'],
'short_description'=>substr(strip_tags(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $row['DESCRIPTION'])),0,50),
'brand_id'=>$row['BRAND'],
'price'=>$row['PRICE'],
]);
$totalInsert++;
}catch(\Throwable | \Error | \Exception $e){
die($e->getMessage());
}
}else{
#update products
DB::table('shop_products')->where('slug',$slug)->update([
'description'=>$row['DESCRIPTION'],
'price'=>$row['PRICE'],
]);
$totalUpdated++;
}
}
else{
#Insert into translation
$countryId = $countryIdsArr[$lang];
$exist = DB::table('shop_products_translation')
->where('slug',$slug)
->where('country_id',$countryId)
->count();
if(!$exist){
$productId = DB::table('shop_products')->where('provider_product_id',$row['ID'])->value('id');
if($productId){
DB::table('shop_products_translation')->insert([
'product_id'=>$productId,
'country_id'=>$countryId,
'title'=>$row['NAME'],
'slug'=>$slug,
'description'=>$row['DESCRIPTION'],
'short_description'=>substr(strip_tags( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $row['DESCRIPTION'])),0,50)
]);
$totalInsert++;
}
}else{
#update products
DB::table('shop_products_translation')->where('slug',$slug)->update([
'description'=>$row['DESCRIPTION'],
]);
$totalUpdated++;
}
}
}catch(\Throwable | \Error | \Exception $e){
die($e->getMessage());
}
}#End of data for loop
}#End of filesArr
}#End of productFilePathArr
echo("Done... $totalInsert records inserted...$totalUpdated records updated");
$this->info("ImportBigbuyProducts Cummand Run successfully!\n");
}
}
Please or to participate in this conversation.