从sub1.example.local(本地主机)到sub2.example.local(本地主机)的cURL/Guzzle请求使用相同的数据库

从sub1.example.local(本地主机)到sub2.example.local(本地主机)的cURL/Guzzle请求使用相同的数据库

问题描述:

我试图发送api请求与guzzle和cURL从sub1.example.local(本地主机)到sub2.example.local(localhost)。这两个laravel 5.4项目。但它使用sub1.example.local的数据库。从sub1.example.local(本地主机)到sub2.example.local(本地主机)的cURL/Guzzle请求使用相同的数据库

即使使用session_write_close();

 $ch = curl_init(); 

     curl_setopt($ch, CURLOPT_URL, "http://sub2.example.local/api/user/login"); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, "email=\"[email protected]\"&password=\"big_secret\""); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLINFO_HEADER_OUT, 1); 
     curl_setopt($ch, CURLOPT_CONNECT_TO, ['hesabatlar.local','80','sub2.example.local','80']); 

     $headers = array(); 
     $headers[] = 'Accept: application/json'; 
     $headers[] = 'Content-Type: application/x-www-form-urlencoded'; 
     $headers[] = 'Host: hr.hesabatlar.local'; 

     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

     session_write_close(); 

     $result = curl_exec($ch); 

     if (curl_errno($ch)) { 
      echo 'Error:' . curl_error($ch); 
     } 
     curl_close ($ch); 

的原因是,请求子2的SUB2 .ENV在不加载和使用SUB1 .ENV文件。所以我得到sub1数据库。欲了解更多信息,请参阅源代码如果在配置文件夹中写入你的配置,它工作正常。

此问题仅在Windows中发生,并且在Linux中正常运行。不确定是什么导致了这个问题。

来源:https://github.com/laravel/framework/issues/16407