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 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同