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 c#里的静态变量为什么是错误的?
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
  • ¥15 arcgis处理土地利用道路 建筑 林地分类
  • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
  • ¥100 寻会做云闪付tn转h5支付链接的技术
  • ¥15 DockerSwarm跨节点无法访问问题