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

Timeout doesn't seem to work #41

Open
emanuelones opened this issue Mar 3, 2019 · 6 comments
Open

Timeout doesn't seem to work #41

emanuelones opened this issue Mar 3, 2019 · 6 comments

Comments

@emanuelones
Copy link

emanuelones commented Mar 3, 2019

I''m using this code

$RCX = new RollingCurlX(25);
$RCX->setTimeout(3000);
$options = [CURLOPT_FOLLOWLOCATION => true];

function response_data($response, $url, $request_info, $user_data, $time) {
    echo strlen($response) . ' - ' . number_format($time, 2) . ' - ' . $response . '<br />'; //array returned by curl_getinfo($ch), plus a couple extras
}

foreach($urls as $url){
    $RCX->addRequest($url, '', 'response_data', '', $options);
}

$RCX->execute();

But the $RCX->setTimeout(3000); doesn't seem to work, the total execution time of the script is ~5 seconds with or without the timeout. Am i doing something wrong?

Thank you!

@Ljz7
Copy link

Ljz7 commented Mar 3, 2019

Hello, the timeout property is in milisecond. The timeout you set is 3seconds. Although, it's a timeout by request. If you have 10 urls to curl, it will last maximum 30 seconds.

Hope it helps.

@emanuelones
Copy link
Author

it doesn't work... the script is executing in the same time with or without timeout :(.

P.S: i have 250 urls, it does a fantastic job in sending all those requests but the problem is that i can't add that timeout

@Ljz7
Copy link

Ljz7 commented Mar 3, 2019

I see. As I read the code, it seems that the _timeout property of this lib is applied to CURLOPT_CONNECTTIMEOUT_MS and to CURLOPT_TIMEOUT_MS curl options (See lines 153 to 163).

So the ~5 seconds you experienced is certainly the addition of the connection time and the transfer time.

A solution could be to create a new property like "_connect_timeout" and use it for the CURLOPT_CONNECTTIMEOUT_MS option.

If that works, you could create a pull request to fix that bug. = )

PS : See the PHP curl-setopt manual for more info about these two options.

@emanuelones
Copy link
Author

Can't seem to be able to get it going :(

@Ljz7
Copy link

Ljz7 commented Mar 5, 2019

Have you tried setting the option to 1500ms ? It's the simpler solution.

@Ljz7
Copy link

Ljz7 commented Mar 5, 2019

Hello @emanuelones

Here is a fix : Ljz7@5de825f

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

No branches or pull requests

2 participants