【问题标题】:How to install external libraries to magento2 without using composer?如何在不使用作曲家的情况下将外部库安装到 magento2?
【发布时间】:2019-03-12 15:45:27
【问题描述】:

我想将 phpmailer 库添加到 magento 2,因此我遵循以下答案 What is the simplest way to use an external php library in a custom magento 2 module? 并且在 localhost 上一切正常。 但是当我尝试运行时

composer require phpmailer/phpmailer 

在服务器上我收到以下错误

Fatal error : out of memory 

我认为这是因为我的服务器上没有足够的内存。

那么有没有另一种方法可以在不使用 composer 的情况下将 phpmailer 库添加到 magento2 中?

【问题讨论】:

  • 您很可能没有足够的内存分配给 PHP - 您应该考虑为您的 php cli 更改您的 php.ini。
  • 如果您不想浪费内存,只需将 php mailer 下载到任何目录并根据需要使用它即可。 Composer 只是使用一个方便的文件来整理所有内容。但是,Magento 相当“重”,因此无论如何增加内存都是值得的。您也可以 composer 将其安装在本地,然后通过 FTP 上传。
  • 我可以提供的最大 php 内存大小是 768MB,这对于运行 composer 来说是不够的。因此,我尝试通过将 phpmailer 库添加到供应商文件并在 composer.json 和 composer.lock 中添加 phpmailer 要求来手动完成作曲家所做的事情,但仍然无法正常工作!如何手动将 phpmailer 放入供应商并在我的自定义模块中使用它?感谢@Joshua 的帮助
  • ^^ @DominicWehrmann
  • 默认情况下 php-cli 在 php.ini 中没有内存限制。仅仅安装 PHPMailer 并不是一项内存密集型任务,所以这里还有其他问题。捆绑静态依赖项通常不是一个好主意,尤其是如果您正在构建一个其他人可能使用的模块,因为这意味着您很容易留下未修补的安全漏洞。 PHPMailer 自述文件告诉你如何手动安装它,但我真的建议你弄清楚你的作曲家出了什么问题,这样你才能以正确的方式去做。

标签: php magento composer-php phpmailer magento2


【解决方案1】:

其实我找到了解决这个问题的方法:

1-在自定义模块文件夹中的目录中添加 phpmailer 库文件夹
2-在块文件中添加以下内容

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

并使用 $mail = new PHPMailer();

更多信息https://github.com/PHPMailer/PHPMailer#installation--loading

【讨论】:

    【解决方案2】:

    您可以通过以下命令设置memory_limit来执行composer:

    php -d memory_limit=1000M /usr/local/bin/composer require phpmailer/phpmailer
    

    【讨论】:

      猜你喜欢
      • 2016-07-18
      • 2018-10-21
      • 1970-01-01
      • 2017-01-23
      • 2018-01-15
      • 2021-10-07
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      相关资源
      最近更新 更多