<bdo id='cziKN'></bdo><ul id='cziKN'></ul>

<small id='cziKN'></small><noframes id='cziKN'>

      <legend id='cziKN'><style id='cziKN'><dir id='cziKN'><q id='cziKN'></q></dir></style></legend>
      1. <i id='cziKN'><tr id='cziKN'><dt id='cziKN'><q id='cziKN'><span id='cziKN'><b id='cziKN'><form id='cziKN'><ins id='cziKN'></ins><ul id='cziKN'></ul><sub id='cziKN'></sub></form><legend id='cziKN'></legend><bdo id='cziKN'><pre id='cziKN'><center id='cziKN'></center></pre></bdo></b><th id='cziKN'></th></span></q></dt></tr></i><div id='cziKN'><tfoot id='cziKN'></tfoot><dl id='cziKN'><fieldset id='cziKN'></fieldset></dl></div>
        <tfoot id='cziKN'></tfoot>

        同一服务器上的两个 Laravel 应用程序相互冲突

        Two Laravel applications on the same server conflicting with one another(同一服务器上的两个 Laravel 应用程序相互冲突)
        <legend id='FCF51'><style id='FCF51'><dir id='FCF51'><q id='FCF51'></q></dir></style></legend>
        <tfoot id='FCF51'></tfoot>

        <small id='FCF51'></small><noframes id='FCF51'>

          <bdo id='FCF51'></bdo><ul id='FCF51'></ul>
            <tbody id='FCF51'></tbody>

              <i id='FCF51'><tr id='FCF51'><dt id='FCF51'><q id='FCF51'><span id='FCF51'><b id='FCF51'><form id='FCF51'><ins id='FCF51'></ins><ul id='FCF51'></ul><sub id='FCF51'></sub></form><legend id='FCF51'></legend><bdo id='FCF51'><pre id='FCF51'><center id='FCF51'></center></pre></bdo></b><th id='FCF51'></th></span></q></dt></tr></i><div id='FCF51'><tfoot id='FCF51'></tfoot><dl id='FCF51'><fieldset id='FCF51'></fieldset></dl></div>

                • 本文介绍了同一服务器上的两个 Laravel 应用程序相互冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 2 个 Laravel 应用程序在同一台服务器上运行.服务器是 Apache 2.4,我设置了虚拟主机来为不同域上的每个应用程序提供服务.

                  I have 2 Laravel applications running on the same server. The server is Apache 2.4 and I have vhosts set up to serve each application on a different domain.

                  第一个应用程序是一个 API,它的 .env 文件是这样设置的:

                  The first application is an API and it's .env file is set up like this:

                  APP_ENV=production
                  APP_KEY=YYYYYYYYYYYYYYYYYY
                  APP_DEBUG=false
                  APP_LOG_LEVEL=debug
                  APP_URL=https://notify.mysite.com
                  APP_DOMAIN=notify.mysite.com
                  
                  
                  DB_CONNECTION=mysql
                  DB_HOST=127.0.0.1
                  DB_PORT=3306
                  DB_DATABASE=notify
                  DB_USERNAME=YYYYYYYYYYYYYYYYYY
                  DB_PASSWORD=YYYYYYYYYYYYYYYYYY
                  
                  BROADCAST_DRIVER=log
                  CACHE_DRIVER=file
                  SESSION_DRIVER=file
                  QUEUE_DRIVER=sync
                  

                  第二个应用程序是一个 UI,它利用了第一个应用程序的 API.它的 .env 文件是这样设置的:

                  The second application is a UI that among other things, utilizes the API from the first application. Its .env file is set up like this:

                  APP_ENV=local
                  APP_KEY=XXXXXXXXXXXXXX
                  APP_DEBUG=true
                  APP_LOG_LEVEL=debug
                  APP_URL=https://asapps.mysite.com
                  APP_DOMAIN=asapps.mysite.com
                  APP_VERSION=1
                  
                  
                  DB_CONNECTION=mysql
                  DB_HOST=127.0.0.1
                  DB_PORT=3306
                  DB_DATABASE=asapps
                  DB_NOTIFY_DATABASE=notify
                  DB_FLIGHT_DATABASE=flights
                  DB_USERNAME=XXXXXXXXXXXXXX
                  DB_PASSWORD=XXXXXXXXXXXXXX
                  
                  BROADCAST_DRIVER=log
                  CACHE_DRIVER=file
                  SESSION_DRIVER=file
                  QUEUE_DRIVER=sync
                  

                  我可以从我的 Swagger 编辑器、Postman 和其他服务器向我的 API 发送消息,并且一切正常.

                  I can send messages to my API from my Swagger editor, from Postman, and from other servers and everything works as expected.

                  我的第二个应用程序本身也可以正常工作.

                  My second application by itself also works as expected.

                  但是,如果我的第二个应用程序向 API 发送请求,则 API 应用程序会抛出此错误:

                  However, if my second application sends a request to the API, the API application throws this error:

                  带有消息SQLSTATE[42S02] 的异常PDOException":未找到基表或视图:1146 表asapps.preprocessor_config"不存在"在 C: otifyvendorlaravelframeworksrcIlluminateDatabaseConnection.php:332

                  exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'asapps.preprocessor_config' doesn't exist' in C: otifyvendorlaravelframeworksrcIlluminateDatabaseConnection.php:332

                  WTH?

                  API 的数据库设置为 DB_DATABASE=notify,当我从其他服务器发送消息时,它肯定会正确使用该连接.那么它为什么要尝试使用第二个应用程序的数据库当我从该应用程序调用 API 时连接???它几乎就像它正在缓存数据库连接并试图继续使用同一个......我该如何阻止它?

                  The database for the API is set to DB_DATABASE=notify and it definitely does properly use that connection when I send messages from other servers. So why the heck is it trying to use the second application's database connection when I call the API from that app??? Its almost like it's caching the DB connection and trying to keep using that same one.... How do I stop that?

                  表 'asapps.preprocessor_config' 不存在'

                  Table 'asapps.preprocessor_config' doesn't exist'

                  推荐答案

                  经过更多挖掘(阅读疯狂的谷歌搜索),我找到了 这里的问题和解决方案

                  After more digging (read frantic googling), I found the problem and solution here

                  最重要的是,当站点 A 接受请求时,php 会为 http 请求的整个长度加载它的 .env 变量.在该请求期间,当站点 A 调用站点 B 时,由于它们在同一台服务器上运行相同的 php,因此 php 仍在使用站点 A 的 .env 并且根本不会单独加载站点 B 的 .env 文件.

                  The bottom line, when site A accepts a request, php loads it's .env variables for the entire length of the http request. During that request, when site A calls site B, since they are on the same server running the same php, php is still using the .env from site A and does not separately load site B's .env file at all.

                  作者更好的解释:

                  创建了带有变量的 .env 文件,这样人们就不会将他们的凭据推送到 github 存储库和其他可以共享源代码的地方.

                  The .env file with the variables was created so that people would not push their credentials to github repositories and other places where they may share the source.

                  现在,作为环境变量,它们在整个 http 请求期间(在本例中为脚本执行)成为系统范围的变量.关键是你有一个运行时间很长的脚本.

                  Now, being environment variables they become system wide for the entire duration of the http request (in this case script execution). The point is that you got a long running script.

                  要找到最终的解决方案,您可以采用以下三种方法之一.

                  To find a definitive solution you could go one of the three ways.

                  ....

                  命名空间"ENV 变量.

                  'namespace' the ENV variables.

                  这篇关于同一服务器上的两个 Laravel 应用程序相互冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  When should use doctrine ORM and when zend-db-table?(什么时候应该使用学说 ORM,什么时候应该使用 zend-db-table?)
                  Doctrine - self-referencing entity - disable fetching of children(Doctrine - 自引用实体 - 禁用获取子项)
                  Doctrine 2, query inside entities(原则 2,实体内部查询)
                  Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
                  Doctrine - OneToMany relation, all result row doesn#39;t fetch in object(Doctrine - OneToMany 关系,所有结果行不获取对象)
                  Doctrine and unrefreshed relationships(教义和未更新的关系)

                    <tbody id='p7Wk2'></tbody>
                • <legend id='p7Wk2'><style id='p7Wk2'><dir id='p7Wk2'><q id='p7Wk2'></q></dir></style></legend>

                    1. <small id='p7Wk2'></small><noframes id='p7Wk2'>

                      <tfoot id='p7Wk2'></tfoot>

                      • <i id='p7Wk2'><tr id='p7Wk2'><dt id='p7Wk2'><q id='p7Wk2'><span id='p7Wk2'><b id='p7Wk2'><form id='p7Wk2'><ins id='p7Wk2'></ins><ul id='p7Wk2'></ul><sub id='p7Wk2'></sub></form><legend id='p7Wk2'></legend><bdo id='p7Wk2'><pre id='p7Wk2'><center id='p7Wk2'></center></pre></bdo></b><th id='p7Wk2'></th></span></q></dt></tr></i><div id='p7Wk2'><tfoot id='p7Wk2'></tfoot><dl id='p7Wk2'><fieldset id='p7Wk2'></fieldset></dl></div>
                            <bdo id='p7Wk2'></bdo><ul id='p7Wk2'></ul>