laravel 为什么导入时出现内存不足错误

ffx8fchx  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(133)

在laravel 10应用程序与igaster/laravel_cities 1.3.12我尝试在控制台导入数据,并得到内存不足的错误:

php  -d memory_limit=6500M  artisan geo:seed UA --append  --chunk=10
Start seeding for UA
Reading File '/mnt/_work_sdb8/wwwroot/lar/quizzes/storage/geo/UA.txt'
   0/100 [>---------------------------]   0%Opening File '/mnt/_work_sdb8/wwwroot/lar/quizzes/storage/geo/hierarchy.txt'
 100/100 [============================] 100% Hierarcy building completed. 0 items loaded

Finished: 0 Countries imported.  10 orphan items skiped
Writing in Database
 100/100 [============================] 100%
Processed Batch 0
   1/100 [>---------------------------]   1%Opening File '/mnt/_work_sdb8/wwwroot/lar/quizzes/storage/geo/hierarchy.txt'
 100/100 [============================] 100% Hierarcy building completed. 0 items loaded

Finished: 0 Countries imported.  10 orphan items skiped
Writing in Database
 100/100 [============================] 100%
Processed Batch 1
   2/100 [>---------------------------]   2%Opening File '/mnt/_work_sdb8/wwwroot/lar/quizzes/storage/geo/hierarchy.txt'
 100/100 [============================] 100% Hierarcy building completed. 1 items loaded

Finished: 0 Countries imported.  9 orphan items skiped
Writing in Database
 100/100 [============================] 100%
Processed Batch 2
   3/100 [>---------------------------]   3%Opening File '/mnt/_work_sdb8/wwwroot/lar/quizzes/storage/geo/hierarchy.txt'
 100/100 [============================] 100% Hierarcy building completed. 0 items loaded

Finished: 0 Countries imported.  10 orphan items skiped
Writing in Database
 100/100 [============================] 100%
Processed Batch 3
   5/100 [=>--------------------------]   5%Opening File '/mnt/_work_sdb8/wwwroot/lar/quizzes/storage/geo/hierarchy.txt'
  46/100 [============>---------------]  46%PHP Fatal error:  Allowed memory size of 6815744000 bytes exhausted (tried to allocate 20480 bytes) in /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/telescope/src/IncomingEntry.php on line 79
PHP Stack trace:
PHP   1. {main}() /mnt/_work_sdb8/wwwroot/lar/quizzes/artisan:0
PHP   2. Illuminate\Foundation\Console\Kernel->handle($input = class Symfony\Component\Console\Input\ArgvInput { protected $definition = class Symfony\Component\Console\Input\InputDefinition { private array $arguments = [...]; private int $requiredCount = 1; private ?Symfony\Component\Console\Input\InputArgument $lastArrayArgument = NULL; private ?Symfony\Component\Console\Input\InputArgument $lastOptionalArgument = class Symfony\Component\Console\Input\InputArgument { ... }; private array $options = [...]; private array $negations = [...]; private array $shortcuts = [...] }; protected $stream = NULL; protected $options = ['append' => TRUE, 'chunk' => '10']; protected $arguments = ['command' => 'geo:seed', 'country' => 'UA']; protected $interactive = TRUE; private array $tokens = [0 => 'geo:seed', 1 => 'UA', 2 => '--append', 3 => '--chunk=10']; private array $parsed = [] }, $output = class Symfony\Component\Console\Output\ConsoleOutput { private int ${Symfony\Component\Console\Output\Output}verbosity = 32; private Symfony\Component\Console\Formatter\OutputFormatterInterface ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { private bool $decorated = TRUE; private array $styles = [...]; private Symfony\Component\Console\Formatter\OutputFormatterStyleStack $styleStack = class Symfony\Component\Console\Formatter\OutputFormatterStyleStack { ... } }; private ${Symfony\Component\Console\Output\StreamOutput}stream = resource(2) of type (stream); private Symfony\Component\Console\Output\OutputInterface $stderr = class Symfony\Component\Console\Output\StreamOutput { private int ${Symfony\Component\Console\Output\Output}verbosity = 32; private Symfony\Component\Console\Formatter\OutputFormatterInterface ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { ... }; private $stream = resource(3) of type (stream) }; private array $consoleSectionOutputs = [] }) /mnt/_work_sdb8/wwwroot/lar/quizzes/artisan:35
...
PHP  27. Illuminate\Events\Dispatcher->dispatch($event = class Illuminate\Log\Events\MessageLogged { public $level = 'warning'; public $message = 'Implicit conversion from float 46.58585890557657 to int loses precision in /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/symfony/console/Helper/ProgressBar.php on line 362'; public $context = [] }, $payload = *uninitialized*, $halt = *uninitialized*) /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/framework/src/Illuminate/Log/Logger.php:248
PHP  28. Illuminate\Events\Dispatcher->invokeListeners($event = 'Illuminate\\Log\\Events\\MessageLogged', $payload = [0 => class Illuminate\Log\Events\MessageLogged { public $level = 'warning'; public $message = 'Implicit conversion from float 46.58585890557657 to int loses precision in /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/symfony/console/Helper/ProgressBar.php on line 362'; public $context = [...] }], $halt = FALSE) /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:266
PHP  29. Illuminate\Events\Dispatcher->Illuminate\Events\{closure:/mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:453-459}($event = 'Illuminate\\Log\\Events\\MessageLogged', $payload = [0 => class Illuminate\Log\Events\MessageLogged { public $level = 'warning'; public $message = 'Implicit conversion from float 46.58585890557657 to int loses precision in /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/symfony/console/Helper/ProgressBar.php on line 362'; public $context = [...] }]) /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:286
PHP  30. Laravel\Telescope\Watchers\LogWatcher->recordLog($event = class Illuminate\Log\Events\MessageLogged { public $level = 'warning'; public $message = 'Implicit conversion from float 46.58585890557657 to int loses precision in /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/symfony/console/Helper/ProgressBar.php on line 362'; public $context = [] }) /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:458
PHP  31. Laravel\Telescope\IncomingEntry::make(...$arguments = variadic(['level' => 'warning', 'message' => 'Implicit conversion from float 46.58585890557657 to int loses precision in /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/symfony/console/Helper/ProgressBar.php on line 362', 'context' => []])) /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/telescope/src/Watchers/LogWatcher.php:52
PHP  32. Laravel\Telescope\IncomingEntry->__construct($content = ['level' => 'warning', 'message' => 'Implicit conversion from float 46.58585890557657 to int loses precision in /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/symfony/console/Helper/ProgressBar.php on line 362', 'context' => []], $uuid = *uninitialized*) /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/telescope/src/IncomingEntry.php:92
PHP  33. array_merge(...$arrays = variadic(['hostname' => 'master-at-home'])) /mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/telescope/src/IncomingEntry.php:79

   Symfony\Component\ErrorHandler\Error\FatalError

  Allowed memory size of 6815744000 bytes exhausted (tried to allocate 20480 bytes)

  at vendor/laravel/telescope/src/IncomingEntry.php:79
     75▕         $this->uuid = $uuid ?: (string) Str::orderedUuid();
     76▕
     77▕         $this->recordedAt = now();
     78▕
  ➜  79▕         $this->content = array_merge($content, ['hostname' => gethostname()]);
     80▕
     81▕         // $this->tags = ['hostname:'.gethostname()];
     82▕     }
     83▕

      +31 vendor frames
  32  artisan:35
      App\Console\Kernel::handle("class Symfony\Component\Console\Input\ArgvInput { protected $definition = class Symfony\Component\Console\Input\InputDefinition { private array $arguments = [...]; private int $requiredCount = 1; private ?Symfony\Component\Console\Input\InputArgument $lastArrayArgument = NULL; private ?Symfony\Component\Console\Input\InputArgument $lastOptionalArgument = class Symfony\Component\Console\Input\InputArgument { ... }; private array $options = [...]; private array $negations = [...]; private array $shortcuts = [...] }; protected $stream = NULL; protected $options = ['append' => TRUE, 'chunk' => '10']; protected $arguments = ['command' => 'geo:seed', 'country' => 'UA']; protected $interactive = TRUE; private array $tokens = [0 => 'geo:seed', 1 => 'UA', 2 => '--append', 3 => '--chunk=10']; private array $parsed = [] }", "class Symfony\Component\Console\Output\ConsoleOutput { private int ${Symfony\Component\Console\Output\Output}verbosity = 32; private Symfony\Component\Console\Formatter\OutputFormatterInterface ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { private bool $decorated = TRUE; private array $styles = [...]; private Symfony\Component\Console\Formatter\OutputFormatterStyleStack $styleStack = class Symfony\Component\Console\Formatter\OutputFormatterStyleStack { ... } }; private ${Symfony\Component\Console\Output\StreamOutput}stream = resource(2) of type (stream); private Symfony\Component\Console\Output\OutputInterface $stderr = class Symfony\Component\Console\Output\StreamOutput { private int ${Symfony\Component\Console\Output\Output}verbosity = 32; private Symfony\Component\Console\Formatter\OutputFormatterInterface ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter...")

  33  artisan:0
      {main}()

   Whoops\Exception\ErrorException

  Allowed memory size of 6815744000 bytes exhausted (tried to allocate 20480 bytes)

  at vendor/laravel/telescope/src/IncomingEntry.php:79
     75▕         $this->uuid = $uuid ?: (string) Str::orderedUuid();
     76▕
     77▕         $this->recordedAt = now();
     78▕
  ➜  79▕         $this->content = array_merge($content, ['hostname' => gethostname()]);
     80▕
     81▕         // $this->tags = ['hostname:'.gethostname()];
     82▕     }
     83▕

      +1 vendor frames
  2   [internal]:0
      Whoops\Run::handleShutdown()

字符串
我在我的操作系统中,在我在/etc/php/8.2/cli/php. ini中设置了7056 M,参数memory_limit = 7056 M:

# free
               total        used        free      shared  buff/cache   available
Mem:         8040668     1679136     4623984      208516     1737548     5900784
Swap:        2104476           0     2104476
# php -r "echo ini_get('memory_limit').PHP_EOL;"
7056M
# php -v
PHP 8.2.11 (cli) (built: Oct  6 2023 09:47:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.11, Copyright (c), by Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
# uname -a
Linux master-at-home 6.2.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct  6 10:23:26 UTC 2 x86_64 x86_64 x86_64 GNU/Linux


文件UA.txt有6.8 MiB -它不是很大,为什么我得到这个错误,以及如何修复它?

djmepvbi

djmepvbi1#

如果你看一下错误被抛出的位置,你会发现它是一个库:
PHP致命错误:/mnt/_work_sdb8/wwwroot/lar/quizzes/vendor/laravel/telescope/src/IncomingEntry.php第79行
如果你找到了package in packagist.org,你可以读到它是“An elegant debug assistant for the Laravel framework”。调试工具经常收集变量以显示它们,当你处理非常大的数据集时,这是你不想要的。要么完全禁用助手,要么检查它是否提供了避免这种情况的设置。
根据documentation,您可以禁用数据收集。这看起来值得一试:

'enabled' => env('TELESCOPE_ENABLED', true),

字符串

相关问题