I've inherited a (L5.5) project which when you hit one route makes a Curl request on API endpoint defined in the same project. Without getting in the reasons why it's done and what could I do to make it better, I'd like to know why do those requests end up in an infinite loop and I can't do anything but to kill the process and run artisan serve again.
$url = route($route_name, Arr::get($params, 'route_params', []));
if ($token = Session::get('access_token')) {
$params['access_token'] = $token;
}
$data = http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
$url resolves to http://127.0.0.1:8000/api/login.
When it comes to curl_exec it just gets stuck and it never hits the endpoint controller method.
What could be the cause of this? Any ideas how to debug it?