Skip to content

[BUG] After closing the cURL-handle it can not be used with curl_error #1

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

Closed
estebanthebad opened this issue Apr 11, 2022 · 3 comments

Comments

@estebanthebad
Copy link

estebanthebad commented Apr 11, 2022

https://github.com/sms77io/php-client/blob/ec0339d72bcdfa930b80ab1c8cd2e2838b944d46/src/BaseClient.php#L97-L102

PHP 7.4.24

curl_error needs to be called before curl_close.

Or the warning 'curl_error(): supplied resource is not a valid cURL handle resource' and subsequently an exception 'Uncaught Error: Wrong parameters for UnexpectedValueException' (as it is not a string) is thrown.

It seems you put the code upside down in that spot. 'Found that bug when curl wanted to complain about missing SSL klimborium.

@estebanthebad
Copy link
Author

estebanthebad commented Apr 11, 2022

Btw. please also add the error code, like so:

 throw new UnexpectedValueException(curl_error($ch), curl_errno($ch)); 

Also it would be helpful to somehow indicate, that this is an error returned by cURL, because cURL in PHP does a really bad job of revealing of who issued the error. I fixed the code like so:

        $res = curl_exec($ch);

        if (false === $res) {
            throw new UnexpectedValueException("\n\ncURL error message:\n".curl_error($ch)."\n\ncURL error code:\n".curl_errno($ch)."\n\n", curl_errno($ch));
        }

        curl_close($ch);

... but a cURLException would be beautiful:

        $res = curl_exec($ch);

        if (false === $res) {
            throw new cURLException("\n\ncURL error message:\n".curl_error($ch)."\n\ncURL error code:\n".curl_errno($ch)."\n\n", curl_errno($ch));
        }

        curl_close($ch);

Thanks!

@estebanthebad estebanthebad changed the title After closing the cURL-handle it can not be used with curl_error [BUG] After closing the cURL-handle it can not be used with curl_error Apr 28, 2022
@matthiez
Copy link
Contributor

matthiez commented May 6, 2022

thanks for reporting @estebanthebad will fix asap in the next release but im quite busy with other stuff atm - feel free to open a pull request on your own though :)

@offizium-berndstorath
Copy link

@matthiez Does this problem still persist? Because curl_close is still called before curl_error

@cl77 cl77 closed this as completed in 11124cb Apr 26, 2024
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

3 participants