Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cURL Timeout Not Working Properly #10

Open
LeeThompson opened this issue May 19, 2023 · 7 comments
Open

cURL Timeout Not Working Properly #10

LeeThompson opened this issue May 19, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@LeeThompson
Copy link
Contributor

LeeThompson commented May 19, 2023

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)

@gaffling
Copy link
Owner

If you use it like this:

function load($url, $DEBUG, $consoleMode = false, $timeOut = 60) {
  if (function_exists('curl_version')) {
    $timeOut = getGlobal('curl_timeout');
    if (!isset($timeOut )) { $timeOut = 60; }

$timeOut = getGlobal('curl_timeout'); is already set before the function call, so I would implement it like this:

function load($url, $DEBUG, $consoleMode = false, $timeOut = 60) {
  if (function_exists('curl_version')) {
    if (!isset($timeOut )) { $timeOut = 60; }

@gaffling gaffling added the enhancement New feature or request label May 22, 2023
@LeeThompson
Copy link
Contributor Author

It's being used by the fallback (non curl) as well, but I'm restructuring it a bit. The above is just a quick fix.

@gaffling
Copy link
Owner

I will be happy with every update-request and promise to merge it ASAP ;-)

@LeeThompson
Copy link
Contributor Author

I'll see if I can do a special branch for this hotfix. My main branch is in the middle of some major rework (including supporting a config file).

@LeeThompson
Copy link
Contributor Author

Nevermind, it looks like you got it, that should be enough for now! :)

@gaffling
Copy link
Owner

No Stress, we can do it all in one Step if you like

@LeeThompson
Copy link
Contributor Author

I'm using #9 for my working on list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants