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

时间:2017-10-16 07:31:28

标签: php laravel curl laravel-5

我正在尝试使用guzzle和cURL从sub1.example.local(localhost)发送api请求到sub2.example.local(localhost)。两个laravel 5.4项目。但它使用sub1.example.local的数据库。

即使使用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@example.com\"&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);

1 个答案:

答案 0 :(得分:1)

原因是当没有加载sub2 .env的子2时,使用了sub1 .env文件。所以我得到了sub1数据库。有关详细信息,请参阅源。如果在配置文件夹中编写配置,它可以正常工作。

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

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

相关问题