Stichoza / google-translate-php

🔤 Free Google Translate API PHP Package. Translates totally free of charge.
MIT License
1.79k stars 380 forks source link

I use the IP of a VPN server as a proxy, I wonder why it doesn't work when I use 'https' instead? #193

Closed richardsonoge closed 10 months ago

richardsonoge commented 11 months ago

Here's my code:

<?php
require_once 'vendor/autoload.php'; // Include Composer's autoloader
use Stichoza\GoogleTranslate\GoogleTranslate;

// $tr = new GoogleTranslate('fr');
$tr = new GoogleTranslate('fr');
// Set proxy to tcp://localhost:8090
$tr->setOptions([
    'proxy' => [
        'http' => 'tcp://5.78.95.239'
    ]
]);
$text = $tr->translate('Hello World!');
echo $text; // Output: en

This code works with 'http'. Why doesn't it work with 'https'? Could I check if it really takes this proxy with 'http' into account? How can I check this?

Stichoza commented 11 months ago

Where cannot see where you specify http or https 🤔

richardsonoge commented 11 months ago

Where cannot see where you specify http or https 🤔

If I use this "'https' => 'tcp://5.78.95.239'" is preferred. It doesn't work and I'm not even 100% sure if it works "'http' => 'tcp://5.78.95.239'"? Although it has translated the text. But how can I check it?

Stichoza commented 11 months ago

Got it.

The translation URL starts with https://, so by specifying proxy for http only, makes no difference. Request is being sent directly without proxy.

You can set proxy for all protocols like this:

$tr->setOptions([
    'proxy' =>  'tcp://5.78.95.239', // <-- Proxy for all protocols
]);

The issue is with proxy itself, I recommend testing proxy separately by a Guzzle client. In your case:

$client = new GuzzleHttp\Client();

$client->request('GET', 'https://dummyjson.com/products', ['proxy' => 'tcp://5.78.95.239']);
richardsonoge commented 11 months ago

Got it.

The translation URL starts with https://, so by specifying proxy for http only, makes no difference. Request is being sent directly without proxy.

You can set proxy for all protocols like this:

$tr->setOptions([
    'proxy' =>  'tcp://5.78.95.239', // <-- Proxy for all protocols
]);

The issue is with proxy itself, I recommend testing proxy separately by a Guzzle client. In your case:

$client = new GuzzleHttp\Client();

$client->request('GET', 'https://dummyjson.com/products', ['proxy' => 'tcp://5.78.95.239']);

It doesn't work. Can you give me several proxies so that Google doesn't temporarily suspend the translation? I think there will be a large volume of visitors to my site and I won't have enough money to pay for the Google api key. Is there a way to create several 100% working proxies so that Google doesn't temporarily block the translation?

Stichoza commented 10 months ago

Sorry, I cannot provide any proxy server addresses.

Closing issue w/ #194