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

Call to undefined function DeepL\curl_version() in deeplcom\deepl-php\src\Translator.php:738 #29

Open
Radon8472 opened this issue Jun 30, 2023 · 3 comments

Comments

@Radon8472
Copy link

Radon8472 commented Jun 30, 2023

I tried to change the http-client like shown in the README section - Custom HTTP client.

What results in Error:

 Call to undefined function DeepL\curl_version() in deeplcom\deepl-php\src\Translator.php:738

Here is my code to find this error:

$client = new \GuzzleHttp\Client([
    'handler' => new \GuzzleHttp\Handler\StreamHandler()
]);

$translator = new \DeepL\Translator($authKey);
$translator->translateText($text, $source, $target, [
    TranslatorOptions::HTTP_CLIENT => $client
]);

So it seems that even when you chance the HttpClient, the Translator Class still tries to use method/functions related to Curl HttpClient for building the user-agend string.

Suggestion to fix:

  1. check which Guzzle handler is used
  2. Only is a handler is used, that extends CurlHandler, set $libraryInfoStr to " curl/$curlVer"
  3. for other Handler, either don`t add this info, or find a way to get similar infos from the other Handler classes
@JanEbbing
Copy link
Member

Thanks for reporting this. I didn't want the spaghetti code in the constructUserAgentString, but it seems it needs to know about a bunch of things to properly report. This will be fixed in the next patch.

@JanEbbing
Copy link
Member

Hi @Radon8472 , I tested my changes that remove this just now by building PHP from source without the cURL extension, but deepl-php has curl-ext as part of its requirements at the moment, so it won't install. Do you get this error with the cURL extension installed? You can check this for example with php -i | grep curl. The output is empty when you don't have the extension installed.

@Radon8472
Copy link
Author

Radon8472 commented Jul 12, 2023

Hi @Radon8472 , I tested my changes that remove this just now by building PHP from source without the cURL extension, but deepl-php has curl-ext as part of its requirements at the moment, so it won't install. Do you get this error with the cURL extension installed? You can check this for example with php -i | grep curl. The output is empty when you don't have the extension installed.

You are right. in My local dev system based on xampp, I dont have this error when I activate curl.
But when I push the files to my life system (where I don`t have curl) I get the error.

You are using guzzle, and guzzle can run fine without curl using the native php streams or socket based Handlers, so I would recommend to move the curl dependency from the require section to suggested.

Otherwise you would stop everybody without curl extension from using deepl, and I see no reason for this, when you are using guzzle, what is made to be useable with native php too.

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