-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Labels
Description
Laravel Version
11.30.0
PHP Version
8.3.9
Database Driver & Version
MySQL 8
Description
Recently, I've been getting some Curl 28
errors relating to time outs sooner than the timeout specified on the Http
client. This is strange and has been intermittently happening for a few weeks now.
Despite passing a number in to the timeout
method, e.g: 25, I'm seeing errors cutting off sooner:
cURL error 28: Operation timed out after 5001 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://www.pixiedustdancewear.co.uk
Steps To Reproduce
I have a method that builds up the HTTP client:
/**
* HTTP type
*
* @return object
*/
public function getHttpMonitorResponse($monitor, $timeout)
{
$url = $monitor->url;
if (str_contains($url, 'cachebuster={timestamp}')) {
$timestamp = Carbon::now()->timestamp;
$url = str_replace('cachebuster={timestamp}', 'cachebuster='.$timestamp, $url);
}
$headers = [
'User-Agent' => 'Mozilla/5.0+(compatible; DomainMonitor/2.0; https://domain-monitor.io/)',
];
$payload = null;
if ($monitor->http_body) {
try {
$payload = json_decode($monitor->http_body, true);
} catch (\Exception $e) {
}
}
$client = Http::withHeaders($headers)->timeout($timeout);
// prevent SSL errors when debug is on
if (config('app.debug')) {
$client = $client->withOptions([
'verify' => false,
]);
}
// set authentication
$client = match ($monitor->auth_type) {
'basic' => $client->withBasicAuth($monitor->username, $monitor->password),
'digest' => $client->withDigestAuth($monitor->username, $monitor->password),
'token' => $client->withToken($monitor->password),
default => $client,
};
// set HTTP method
$client = match ($monitor->method) {
'get' => $client->get($url),
'head' => $client->head($url),
'delete' => $client->delete($url),
'post' => $client->post($url, $payload),
'put' => $client->put($url, $payload),
'patch' => $client->patch($url, $payload),
default => $client->get($url),
};
return $client;
}