如何在 laravel 的实时服务器上解决此错误?实时、器上、错误、如何在

2023-09-06 16:06:36 作者:我拖着躯壳沿途寻找的快乐

我已经在本地成功安装了这个包 composer 需要 spatie/laravel-image-optimizer,但是当我尝试在实时服务器上安装时出现这个错误

no@zz607:/var/www/html$ composer 需要 spatie/laravel-image-优化器使用 ^1.4 版进行 spatie/laravel-image-optimizer./composer.json 已更新使用包信息加载作曲家存储库更新依赖项(包括 require-dev)mmap() 失败:[12] 无法分配内存mmap() 失败:[12] 无法分配内存mmap() 失败:[12] 无法分配内存PHP致命错误:内存不足(分配544395264)(试图分配20480字节)在/usr/share/php/Composer/Repository/ComposerRepository.php 在第 321 行致命错误:内存不足(已分配 544395264)(试图分配20480 字节)在/usr/share/php/Composer/Repository/ComposerRepository.php 在第 321 行

服务器信息

解决方案 IIS7 出现HTTP 500内部服务器错误解决方案

您的问题可能与只有 1gb 的 RAM 并且没有内存交换的事实有关,所以让我们创建并启用它以在作曲家执行的时间.

按照以下步骤操作:

1) 创建 1gb 内存 swapfile:

$ sudo fallocate -l 1G/swapfile$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576

此命令创建了 1GB 大小的 /swapfile 文件.

2) 配置要交换的文件:

$ sudo chmod 600/swapfile$ sudo mkswap/swapfile

3) 启用交换:

$ sudo swapon/swapfile

要查看结果,您可以运行 free -m 或查看 htop

示例:$ sudo free -m

 总计 usada livre compart.buff/cache disponível电话:7664 1052 3436 56 3175 6259交换:1024 0 1024

示例:$ sudo swapon --show

NAME TYPE SIZE USED PRIO/swapfile 文件 1G 0B -2

请测试一下.

I have installed this package success locally composer require spatie/laravel-image-optimizer, but when I tried to install on the live server I got this errors

no@zz607:/var/www/html$  composer require spatie/laravel-image- 
optimizer
Using version ^1.4 for spatie/laravel-image-optimizer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 544395264) (tried to 
allocate 20480 bytes) in 
/usr/share/php/Composer/Repository/ComposerRepository.php on line 321

Fatal error: Out of memory (allocated 544395264) (tried to allocate 
 20480 bytes) in 
 /usr/share/php/Composer/Repository/ComposerRepository.php on line 321

server info

解决方案

Your problem is related to the probable fact of having only 1gb of RAM and not having memory swap, so let's create and enable it to take some time off at the time of composer execution.

Folow this steps:

1) Creating 1gb memory swapfile:

$ sudo fallocate -l 1G /swapfile

$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576

This command created the /swapfile file with 1GB in size.

2) Configuring file to swap:

$ sudo chmod 600 /swapfile

$ sudo mkswap /swapfile

3) Enable swap:

$ sudo swapon /swapfile

To see result you can run free -m or see on htop

Example: $ sudo free -m

              total       usada       livre    compart.  buff/cache  disponível
Mem.:          7664        1052        3436          56        3175        6259
Swap:          1024           0        1024

Example: $ sudo swapon --show

NAME      TYPE SIZE USED PRIO
/swapfile file   1G   0B   -2

Test please.