DeepLcom / deepl-php

Official PHP library for the DeepL language translation API.
MIT License
202 stars 23 forks source link

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

Open Radon8472 opened 1 year ago

Radon8472 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.