Php Guzzle服务器异常导致“500内部服务器错误”响应
我正在尝试使用Lumen和laravel实现一个微服务架构 我使用laravel 5.4作为一个通道,使用Lumen 5.4作为一个微服务 这里我在我的laravel项目中使用GuzzleHTTP版本6.3,试图使用microService API,但是我得到了500个内部服务器错误 我正在本地主机上尝试这个 这就是我提出请求的方式:Php Guzzle服务器异常导致“500内部服务器错误”响应,php,laravel-5,microservices,guzzle,lumen,Php,Laravel 5,Microservices,Guzzle,Lumen,我正在尝试使用Lumen和laravel实现一个微服务架构 我使用laravel 5.4作为一个通道,使用Lumen 5.4作为一个微服务 这里我在我的laravel项目中使用GuzzleHTTP版本6.3,试图使用microService API,但是我得到了500个内部服务器错误 我正在本地主机上尝试这个 这就是我提出请求的方式: public function get_posts(){ try { $client = new Client(); //GuzzleHt
public function get_posts(){
try {
$client = new Client(); //GuzzleHttp\Client
$res = $client->request('GET', 'http://localhost/micro/posts_micro_service/public/posts');
if($res->getStatusCode() == "200"){
echo $res->getBody();
}else{
return response()->json(['status',"error"]);
}
} catch (ClientException $e) {
echo Psr7\str($e->getRequest());
echo Psr7\str($e->getResponse());
}
}
我得到了这个错误:
(1/1) ServerException
Server error: `GET http://localhost/micro/posts_micro_service/public/posts` resulted in a `500 Internal Server Error` response:
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
(truncated...)
in RequestException.php (line 113)
(1/1)服务器异常
服务器错误:`GEThttp://localhost/micro/posts_micro_service/public/posts`导致“500内部服务器错误”响应:
(截断…)
在RequestException.php中(第113行)
问题是因为Lumen和Laravel使用同一台机器,共享同一个环境,所以当我调用环境变量时,它们被覆盖了 使用新端口运行php服务器例如:-
对于Laravel:
php -S localhost:8000 -t public
对于流明:
php -S localhost:8001 -t public
这对我有用。使用此方法而不是设置vhost。那么您想出了什么解决方案