in my application I have two laravel 5.2 servers running and they need to interact with each other to get resources using guzzle.
In my server 1, I use League Transformer to return some data, but the data needs to include a resource from my server 2 I get the data using guzzle in the transform function:
public function transform(MyModel $model) {
$client = new Client();
$result = $client->request('GET', 'localhost:8000/api/companies/'.$model->company_id);
$company= $result->getBody()->getContents();
$data = [
'id' => (int) $model->id,
'name' => $model->name,
'status' => $model->status,
];
$data['company'] = json_decode($company);
return $data;
}
When I make a request to get this resource to localhost:4040/api/models/1
I get this response:
"data": {
"id": 1,
"name": "John Doe",
"status": "active",
"company": {
"data": {
"id": 1,
"name": "My Company",
}
}
The problem I'm facing is when I need to access MyModel (stored in server 1) from server 2 using guzzle, because I need to make a request to server 1:
$result = $client->request('GET', 'localhost:4040/api/models/'.$model->_id);
and server 1 needs to make a request to server 2 (in the transformer) to get the company. This makes the client to wait forever and never get a response. I tried using Async request, but I get an empty response, and if I force the promise to wait, it also hangs forever.