Home > Software design >  How can I specify a proxy for Mailjet with the Php wrapper?
How can I specify a proxy for Mailjet with the Php wrapper?

Time:09-30

On my new server, I have to use a proxy to make the different API calls to other services.

I'm using Mailjet, and making the calls with the official PHP Wrapper (with no composer : https://github.com/mailjet/mailjet-apiv3-php-no-composer ).

I try to configure the proxy like that :

$mj = new \Mailjet\Client(
                APIKEY,
                APIKEY2,
                true,
                [
                    'version' => 'v3.1',
                    'connect_timeout' => 4,
                    'proxy' => [
                        'http' => someurl,
                        'https' => someurl
                    ]
                ]
            );

As you can see I'm also trying to edit the "CONNECT_TIMEOUT" variable. (I tried to set the variables in uppercase too, same result)

Unfortunaly, through all my tests I could have observe that only version and url variables are considered and set as asked. Any other variable, random or supposed to be taken care of, are not setted and stay with their default value.

I guess I'm not configuring as I should, perhaps those options should be elsewhere in the call, but even the Mailjet Support couldn't have inform me...

In the mean time I edited the /Mailjet/src/Mailjet/Client.php file from

 private $requestOptions = [
    self::TIMEOUT => 15,
    self::CONNECT_TIMEOUT => 2,
];

to

 private $requestOptions = [
    self::TIMEOUT => 15,
    self::CONNECT_TIMEOUT => 4,
    self::PROXY => someurl
];

It works, but I prefer not having to edit this file and pass the variables as I should.

CodePudding user response:

That class has a public method called setConnectionTimeout which you can use in your Client instance (e.g $mj->setConnectionTimeout(4))

  • Related