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

Set CURLOPT_RETURNTRANSFER => true on default #18

Closed
linslin opened this issue May 7, 2015 · 16 comments
Closed

Set CURLOPT_RETURNTRANSFER => true on default #18

linslin opened this issue May 7, 2015 · 16 comments

Comments

@linslin
Copy link
Owner

linslin commented May 7, 2015

Set CURLOPT_RETURNTRANSFER => true on default

@linslin linslin closed this as completed May 7, 2015
linslin pushed a commit that referenced this issue May 7, 2015
@yemexx1
Copy link
Contributor

yemexx1 commented Sep 29, 2015

CURLOPT_RETURNTRANSFER => true works on my local mac, but does not work on ubuntu server. Had to explicitly call $curl->setOption(CURLOPT_RETURNTRANSFER, 1);

@linslin
Copy link
Owner Author

linslin commented Sep 29, 2015

Hey, thanks for your report. Are you using the latest version of version of yii2/curl? Which cURL Version are you using? I will reopen this bug if we are able to reproduce it.

@yemexx1
Copy link
Contributor

yemexx1 commented Sep 29, 2015

Hi Linslin,

cURL Version: curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3

linslin/Yii2-Curl version: 1.0.4

I will reopen this bug if we are able to reproduce it.

Okay.

@linslin
Copy link
Owner Author

linslin commented Sep 29, 2015

Thanks, could you send me a debug output of $this->getOptions() near line 280 in curl.php? Without setting $curl->setOption(CURLOPT_RETURNTRANSFER, 1); manually. Are you sending multiple request in a row? If yes, are you using the "reset" function?

@yemexx1
Copy link
Contributor

yemexx1 commented Sep 29, 2015

Oops! sorry my bad. Used "linslin/yii2-curl": "*" in composer require and 1.0.4 was pulled on local but 1.0.3 was pulled on server.

$this->getOptions() debug 1.0.3

array(7) { [10036]=> string(3) "GET" [20011]=> object(Closure)#115 (3) { ["static"]=> array(1) { ["body"]=> &string(0) "" } ["this"]=> object(linslin\yii2\curl\Curl)#116 (4) { ["response"]=> NULL ["responseCode"]=> NULL ["_options":"linslin\yii2\curl\Curl":private]=> array(2) { [10036]=> string(3) "GET" [20011]=> RECURSION } ["_defaultOptions":"linslin\yii2\curl\Curl":private]=> array(5) { [10018]=> string(15) "Yii2-Curl-Agent" [13]=> int(30) [78]=> int(30) [19913]=> bool(false) [42]=> bool(false) } } ["parameter"]=> array(2) { ["$curl"]=> string(10) "" ["$data"]=> string(10) "" } } [10018]=> string(15) "Yii2-Curl-Agent" [13]=> int(30) [78]=> int(30) [19913]=> int(0) [42]=> int(0) }

$this->getOptions() debug 1.0.4 (after running composer update)

array(7) { [10036]=> string(3) "GET" [20011]=> object(Closure)#115 (3) { ["static"]=> array(1) { ["body"]=> &string(0) "" } ["this"]=> object(linslin\yii2\curl\Curl)#116 (4) { ["response"]=> NULL ["responseCode"]=> NULL ["_options":"linslin\yii2\curl\Curl":private]=> array(2) { [10036]=> string(3) "GET" [20011]=> RECURSION } ["_defaultOptions":"linslin\yii2\curl\Curl":private]=> array(5) { [10018]=> string(15) "Yii2-Curl-Agent" [13]=> int(30) [78]=> int(30) [19913]=> bool(true) [42]=> bool(false) } } ["parameter"]=> array(2) { ["$curl"]=> string(10) "" ["$data"]=> string(10) "" } } [10018]=> string(15) "Yii2-Curl-Agent" [13]=> int(30) [78]=> int(30) [19913]=> bool(true) [42]=> bool(false) }

Works fine now without $curl->setOption(CURLOPT_RETURNTRANSFER, 1);. Thanks.

@linslin
Copy link
Owner Author

linslin commented Sep 29, 2015

👍

@irthunder
Copy link

Using version 1.0.4. Faced same problem. Fixed by adding
curl_setopt($curl, CURLOPT_RETURNTRANSFER, $this->getOption(CURLOPT_RETURNTRANSFER));
right after
curl_setopt_array($curl, $this->getOptions());

@linslin
Copy link
Owner Author

linslin commented Oct 22, 2015

Hey @irthunder,

thanks for your report. I tried to reproduce it, but with 1.0.4 seems all fine here. Could you take a look at the top of your curl.php file. ->

    /**
     * @var array default curl options
     * Default curl options
     */
    private $_defaultOptions = array(
        CURLOPT_USERAGENT      => 'Yii2-Curl-Agent',
        CURLOPT_TIMEOUT        => 30,
        CURLOPT_CONNECTTIMEOUT => 30,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER         => false,
    );

Is CURLOPT_RETURNTRANSFER => true, set as default? Are you setting some other curl Options?

@irthunder
Copy link

Hi, @linslin
Yes, it's set to true. Also i setup some other options (such as CURLOPT_SSL_VERIFYPEER, CURLOPT_SSL_VERIFYHOST, CURLOPT_TIMEOUT). I investigated that everything is fine until you try to set CURLOPT_RETURNTRANSFER in you own code, then - it doesn't matter what is default value in $_defaultOptions - curl always return only true or false.

@linslin
Copy link
Owner Author

linslin commented Oct 22, 2015

Please check this answer: #22 (comment). Does it effect you?

@irthunder
Copy link

It looks like. I'm using GET / response code = 200.
Thank you!

@linslin
Copy link
Owner Author

linslin commented Oct 22, 2015

So it does work for you by using GET / 200 OK?

@irthunder
Copy link

It does work as i described above - it's returning requested only if CURLOPT_RETURNTRANSFER => true in $_defaultOptions and i did not initialize this option value in my code. Or if it's additional line of code in Curl class. Otherwise - i'm getting true (HTTP 200) or false (HTTP 4xx,5xx).

@linslin
Copy link
Owner Author

linslin commented Oct 22, 2015

Allright, thx so far. I check this behavior tomorrow. Please stand by.

@linslin
Copy link
Owner Author

linslin commented Oct 27, 2015

Hey @irthunder,

so here we are. It looks like this bug was reported before but descriped different. This should be fixed right now for verson 1.0.5 @ #19. Could you checkout the DEV-Branch an retry it? Does this also happen with the upcoming version? THX

@irthunder
Copy link

Hi, @linslin

Tried 1.0.5 - it's OK, CURLOPT_RETURNTRANSFER option works as expected.

Thank you.

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

No branches or pull requests

3 participants