安装最新版本的xampp 8.0.9
后,当我从xampp
面板打开终端时,我有另一个操作系统作为Debian
,
uname -a -r
Linux debian 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux
现在导航到htdocs
文件夹内的php
项目后,我尝试使用composer upadte
来安装和更新composer.json
包,但我得到这个错误:
composer update
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Updating dependencies (including require-dev)
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 798220288) (tried to allocate 32134463 bytes) in /usr/share/php/Composer/Util/RemoteFilesystem.php on line 459
Fatal error: Out of memory (allocated 798220288) (tried to allocate 32134463 bytes) in /usr/share/php/Composer/Util/RemoteFilesystem.php on line 459
当我得到这个错误时,我尝试将memory_limit
更改为php.ini
文件,然后我运行这个命令:
php --ini
输出:
Configuration File (php.ini) Path: /opt/lampp/etc
Loaded Configuration File: /opt/lampp/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
这里memory_limit
是-1
,因为我安装了php 8.0.9
,它没有php
文件夹在/etc/
,我只有php 7.3
php -v
输出:
PHP 8.0.9 (cli) (built: Jul 30 2021 09:12:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
在php 7.3
文件夹中打开php.ini
来更改memory_limit
,此选项值也有-1
现在我如何增加memory_limit
和解决这个问题?
最后运行这个命令没有给我任何输出或结果:
php -d memory_limit=1024M /usr/bin/composer update
try
php -d memory_limit=-1 composer update
,以便独立于ini文件设置限制。
根据php --ini
, php 8的php.ini文件位于/opt/lampp/etc/php.ini中,而不是/etc/
每当我尝试在laravel中使用种子器同时上传10万数据时,我都会遇到同样的问题
- 首先你可以尝试PHP的chunk函数来尝试上传一些数据
然后运行foreach (array_chunk($object_array,1000) as $t) { DB::table('table_name')->insert($t); }
php artisan o:c
- 在终端运行命令
free -m
这是释放你的内存