2

I have a code like this

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Accept: application/json",
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$responseHeaders) {
    $len = strlen($header);
    $header = explode(':', $header, 2);
    if (count($header) < 2)
        return $len;
    $responseHeaders[strtolower(trim($header[0]))][] = trim($header[1]);
    return $len;
});

$response = curl_exec($ch);
$err      = curl_error($ch);

curl_close($ch);

The problem is on

$response = curl_exec($ch);

Is it possible, to proceed, if I dont have response within 2seconds?

If Yes Can you give me idea?

Fil
  • 8,225
  • 14
  • 59
  • 85
  • 1
    I believe you are looking for curl_setopt($ch, CURLOPT_TIMEOUT, 2); . Please refer to the [official_reference](https://www.php.net/manual/en/function.curl-setopt.php) – Ken Lee Oct 31 '21 at 02:49

0 Answers0