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

使用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?

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据