jeudi 6 janvier 2022

/tmp/laravel-excel does not exist

so i am using laravel excel for importing .csv files and because the .csv files contain a lot of data then i running the import using laravel queue with redis driver

everything working just fine at local server at my mac using valet

but the problem occur when i tried the same code at production server at our vps that managed using runcloud

and it is only happen if i am using queue driver beside snyc. so if i change it to use database driver or redis driver then the error come.

after doing multiple debuging i find out that the error is because it can't create \tmp\ files for this plugins for doing import

to help find the key issue here is my configuration

"php": ">=7.1.3",
"maatwebsite/excel": "^3.1",
"laravel/framework": "5.6.*",
"predis/predis": "^1.1", 

and here is stacktrace from laravel.log

[2022-01-06 14:57:14] local.ERROR: File "/tmp/laravel-excel-kzUS1G2AIXnig0Z1VKs5AegK3ar98WRS.csv" does not exist. {"exception":"[object] (InvalidArgumentException(code: 0): File \"/tmp/laravel-excel-kzUS1G2AIXnig0Z1VKs5AegK3ar98WRS.csv\" does not exist. at /home/runcloud/webapps/puskopcuina/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/File.php:137)
[stacktrace]
#0 /home/runcloud/webapps/puskopcuina/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/BaseReader.php(152): PhpOffice\\PhpSpreadsheet\\Shared\\File::assertFile()
#1 /home/runcloud/webapps/puskopcuina/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Csv.php(540): PhpOffice\\PhpSpreadsheet\\Reader\\BaseReader->openFile()
#2 /home/runcloud/webapps/puskopcuina/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Csv.php(349): PhpOffice\\PhpSpreadsheet\\Reader\\Csv->canRead()
#3 /home/runcloud/webapps/puskopcuina/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Csv.php(330): PhpOffice\\PhpSpreadsheet\\Reader\\Csv->loadIntoExisting()
#4 /home/runcloud/webapps/puskopcuina/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php(118): PhpOffice\\PhpSpreadsheet\\Reader\\Csv->load()
#5 [internal function]: Maatwebsite\\Excel\\Jobs\\ReadChunk->handle()
#6 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array()
#7 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#8 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod()
#9 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\\Container\\BoundMethod::call()
#10 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\\Container\\Container->call()
#11 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}()
#12 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#13 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\\Pipeline\\Pipeline->then()
#14 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(49): Illuminate\\Bus\\Dispatcher->dispatchNow()
#15 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(83): Illuminate\\Queue\\CallQueuedHandler->call()
#16 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(326): Illuminate\\Queue\\Jobs\\Job->fire()
#17 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(276): Illuminate\\Queue\\Worker->process()
#18 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\\Queue\\Worker->runJob()
#19 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\\Queue\\Worker->daemon()
#20 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85): Illuminate\\Queue\\Console\\WorkCommand->runWorker()
#21 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#22 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array()
#23 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#24 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod()
#25 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\\Container\\BoundMethod::call()
#26 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Console/Command.php(179): Illuminate\\Container\\Container->call()
#27 /home/runcloud/webapps/puskopcuina/vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute()
#28 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Console/Command.php(166): Symfony\\Component\\Console\\Command\\Command->run()
#29 /home/runcloud/webapps/puskopcuina/vendor/symfony/console/Application.php(1009): Illuminate\\Console\\Command->run()
#30 /home/runcloud/webapps/puskopcuina/vendor/symfony/console/Application.php(273): Symfony\\Component\\Console\\Application->doRunCommand()
#31 /home/runcloud/webapps/puskopcuina/vendor/symfony/console/Application.php(149): Symfony\\Component\\Console\\Application->doRun()
#32 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Symfony\\Component\\Console\\Application->run()
#33 /home/runcloud/webapps/puskopcuina/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\\Console\\Application->run()
#34 /home/runcloud/webapps/puskopcuina/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle()
#35 {main}"} 

update

here is my config/excel.php

<?php

use Maatwebsite\Excel\Excel;

return [
    'exports'            => [

        /*
        |--------------------------------------------------------------------------
        | Chunk size
        |--------------------------------------------------------------------------
        |
        | When using FromQuery, the query is automatically chunked.
        | Here you can specify how big the chunk should be.
        |
        */
        'chunk_size' => 1000,

        /*
        |--------------------------------------------------------------------------
        | Temporary path
        |--------------------------------------------------------------------------
        |
        | When exporting files, we use a temporary file, before storing
        | or downloading. Here you can customize that path.
        |
        */
        'temp_path'  => sys_get_temp_dir(),

        /*
        |--------------------------------------------------------------------------
        | CSV Settings
        |--------------------------------------------------------------------------
        |
        | Configure e.g. delimiter, enclosure and line ending for CSV exports.
        |
        */
        'csv'        => [
            'delimiter'              => ',',
            'enclosure'              => '"',
            'line_ending'            => PHP_EOL,
            'use_bom'                => false,
            'include_separator_line' => false,
            'excel_compatibility'    => false,
        ],
    ],

    'imports' => [

        'heading_row' => [

            /*
            |--------------------------------------------------------------------------
            | Heading Row Formatter
            |--------------------------------------------------------------------------
            |
            | Configure the heading row formatter.
            | Available options: none|slug|custom
            |
            */
            'formatter' => 'slug',
        ],

        'csv' => [
            'delimiter'              => '|',
            'enclosure'              => '"',
            'line_ending'            => PHP_EOL,
            'use_bom'                => false,
            'include_separator_line' => false,
            'excel_compatibility'    => false,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Extension detector
    |--------------------------------------------------------------------------
    |
    | Configure here which writer type should be used when
    | the package needs to guess the correct type
    | based on the extension alone.
    |
    */
    'extension_detector' => [
        'xlsx'     => Excel::XLSX,
        'xlsm'     => Excel::XLSX,
        'xltx'     => Excel::XLSX,
        'xltm'     => Excel::XLSX,
        'xls'      => Excel::XLS,
        'xlt'      => Excel::XLS,
        'ods'      => Excel::ODS,
        'ots'      => Excel::ODS,
        'slk'      => Excel::SLK,
        'xml'      => Excel::XML,
        'gnumeric' => Excel::GNUMERIC,
        'htm'      => Excel::HTML,
        'html'     => Excel::HTML,
        'csv'      => Excel::CSV,
        'tsv'      => Excel::TSV,

        /*
        |--------------------------------------------------------------------------
        | PDF Extension
        |--------------------------------------------------------------------------
        |
        | Configure here which Pdf driver should be used by default.
        | Available options: Excel::MPDF | Excel::TCPDF | Excel::DOMPDF
        |
        */
        'pdf'      => Excel::DOMPDF,
    ],
];


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire