duanjinchi1982
2018-08-17 10:34
浏览 171
已采纳

使用Composer仅在PHP中加载特定依赖项

Let's say that I have a back-end running on a customized PHP environment (no Laravel nor Symfony). It is used as an API server most of the time. But once a day I need to send out some mails. Let's say that I use a dedicated tools for that: Twig to create bodies of the mails, and PHPMailer to send them out. I don't need neither of these to answer the incoming front-end requests.

My question is: can I ask Composer (which I use as a dependency manager) to exclude Twig and PHPMailer when compiling the code to answer the front-end requests?

Obviously, the example here would save me fractions of seconds, and fractions of RAM, but what if I have other dependencies that are used only for other purposes too?

图片转代码服务由CSDN问答提供 功能建议

假设我在自定义的PHP环境中运行后端(没有Laravel或Symfony)。 它大多数时候用作API服务器。 但每天一次我需要发一些邮件。 假设我使用专用工具:Twig创建邮件的主体,PHPMailer将它们发送出去。 我不需要这些来回答传入的前端请求。

我的问题是:我可以要求Composer(我用作依赖管理器)排除Twig和PHPMailer 在编译代码以回答前端请求时?

显然,这里的示例可以节省几分之一秒和RAM的分数,但如果我有其他依赖项,那该怎么办? 仅用于其他目的吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongtang6718 2018-08-17 10:47
    最佳回答

    Obviously, the example here would save me fractions of seconds, and fractions of RAM

    It actually does not save you nothing. Composer's autoloader loads class only when you request it. If you never use Twig or PHPMailer in your frontend request, it will never load it, so no RAM or CPU will be used.

    Basically it already works in a way you would like to.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题