PHP-Grab-Favicon icon indicating copy to clipboard operation
PHP-Grab-Favicon copied to clipboard

cURL Timeout Not Working Properly

Open LeeThompson opened this issue 1 year ago • 7 comments

There is a bug (my fault) where the curl timeout isn't being set properly, this will cause it to hang instead of timing out.

I have fixed it locally but I've changed other things as well and not ready for a PR.

Quick fix is to insert the following two lines in the load function

    $timeOut = getGlobal('curl_timeout');
    if (!isset($timeOut )) { $timeOut = 60; }

Current:

function load($url, $DEBUG, $consoleMode = false, $timeOut = 60) {
  if (function_exists('curl_version')) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERAGENT, getGlobal('curl_useragent'));
    curl_setopt($ch, CURLOPT_VERBOSE, getGlobal('curl_verbose'));
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);

** Hot Fix:**

function load($url, $DEBUG, $consoleMode = false, $timeOut = 60) {
  if (function_exists('curl_version')) {
    $timeOut = getGlobal('curl_timeout');
    if (!isset($timeOut )) { $timeOut = 60; }
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERAGENT, getGlobal('curl_useragent'));
    curl_setopt($ch, CURLOPT_VERBOSE, getGlobal('curl_verbose'));
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);

(It's handled much better in the newer code)

LeeThompson avatar May 19 '23 20:05 LeeThompson