-
Notifications
You must be signed in to change notification settings - Fork 319
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
Remove dependency on Guzzle #94
Conversation
PHPUnit OK (49 tests, 75 assertions)
…. Manual sending message to mailgun API works.
@@ -2,11 +2,13 @@ | |||
"name": "mailgun/mailgun-php", | |||
"description": "The Mailgun SDK provides methods for all API functions.", | |||
"require": { | |||
"guzzlehttp/guzzle": "~5.0" | |||
"guzzlehttp/psr7": "~1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not php-fig/http-message ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. We should not be dependent on Guzzle's implementation here. We should use a message factory.. I'll update in a minute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, We need the implementation for because there are too difficult to handle file upload without it. See here: https://github.com/mailgun/mailgun-php/pull/94/files#diff-72d96caf4bb8f89a5d30eafdff75bbe2R63
First of all. Don't merge this until php-http has reached a stable version. (I'll add that in the PR's description). @RubenKruiswijk @RubenKruiswijk Do you think I should remove |
I removed dependency on |
'defaults'=>[ | ||
'auth' => array(Api::API_USER, $this->apiKey), | ||
'exceptions' => false, | ||
'config' => ['curl' => [ CURLOPT_FORBID_REUSE => true ]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a way to set these defaults (CURLOPT_FORBID_RESUSE and User-Agent header)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that we need to set CURLOPT_FORBID_RESUSE
for backwards compatibility, but why is that needed? I cant find any documentation about why we use it. This is from the official documentation
Pass a long. Set close to 1 to make libcurl explicitly close the connection when done with the transfer. Normally, libcurl keeps all connections alive when done with one transfer in case a succeeding one follows that can re-use them. This option should be used with caution and only if you understand what it does as it can seriously impact performance.
Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the commit that added the CURLOPT_FORBID_RESUSE.
b4b9f0e
Ping @travelton, I know it was over 2 years ago, but do you remember why you added that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nyholm If I recall, it was an internal decision to help force connections between API nodes, thus, improving the overall performance from a customer's perspective.
For example, if you are processing 1,000 API calls, reusing connections, and you land on a node that isn't performing very well, you'd issue 1,000 API calls on that non-performant node. With this option enabled, you effectively force a new connection to a different API node every time. So now, maybe one in every x API calls hits a non-performant API node.
I'm betting this "trick" is obsolete, as the load balancing architecture has rapidly improved/changed over the years. Unfortunately, I don't have the insight to confirm, as I'm not working with the Mailgun team these days. As an outsider looking in, I would remove it from default configurations, and allow it as an "Advanced Option" for tinker-ers that love performance tuning. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your input. Do you know who are on the Mailgun team that can confirm this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nyholm Reached out to the Mailgun team, they confirmed this setting will have no performance benefit due to improvements in load balancing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @travelton. You are awesome!
PHP-HTTP is probably stable now. They will tag a stable version before the end of the year. I've updated this PR to reflect the latest changes in PHP-HTTP. |
Looking forward to this +1 |
+1 on this! What else needs done to get this merged and tagged? |
👍 from me as well. |
Thank you @bshaffer |
Yeah, they did. 😄 The discovery repo is not stable yet though. I am following the discussions in Httplug and in Puli. I can do some updates here to make sure we are closer to a merge. |
Any news on this? The fiasco over at Mandrill has caused me to look to Mailgun for our email platform and the dependency on guzzle v5 is conflicting with my existing codebase that has v6. |
@tomschlick You can temporarily use the following fork in your composer until everything is merged.
|
Don't know how I didn't think of that. I've done it many times before... Tom Schlick On Thu, Feb 25, 2016 at 4:55 PM -0800, "Mark Johnson" notifications@github.com wrote: @tomschlick You can temporarily use the following fork until everything is merged. "repositories": [{ — |
I has been almost 5 months since I've opened this PR and it is now ready for a final review. Please be extra observant to the readme and the new installation instructions. Do they make sense? Do you understand that you need to do one of the following:
After reviewing and fixed the issues you have found I will squash my commits and make sure it is ready for merge. |
Ping @virgofx @captn3m0 @tomschlick @bshaffer @jessespears Do you have any input? |
$mailgun = new \Mailgun\Mailgun('api_key', null, null, true, $client); This is a little crazy with 5 params, 3 of which most people wouldn't touch. Since this is going to be a breaking change, can we get rid of some of the options in construct and throw some of them to their own methods? For instance if we got rid of the SSL = true and the api version it would look much cleaner as $mailgun = new \Mailgun\Mailgun('api_key', 'mydomain.com', $client);
// If you needed those options you could do...
$mailgun->setApiVersion('v2'); // default current version
$mailgun->setSSLEnabled(false); // default true |
Agree with @tomschlick 's comment. @Nyholm I'll review the changes this weekend and provide some feedback. |
Thank you for the review. I agree, the constructor was very bloated with parameters. I removed API version and SSL as you suggested. |
👍 looks good! |
$this->apiKey = $apiKey; | ||
$this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl); | ||
$this->restClient = new RestClient($apiKey, $apiEndpoint, $httpClient); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can we make $apiKey required? I don't think you can use Mailgun without it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, API key should be required. I did not want to make too many BC breaking changes. That's why I left is as it was.
Thank you for your review.
Looks good to me. Only comment was updating the Readme to not have the null options in construct as the first example ... if you wanted to do that .. perhaps make two examples. The first one should always be the simple default for how most people can use the API. The second one could be with a different rest client and different endpoint. And ... wasn't sure was it possible to have a null API key? If it's not, make this parameter not optional. |
When will this be merged? |
Interested in this getting merged ASAP too ;-) |
I have contacted @jessespears and he said he will do his best to have a look at it before the weekend. |
Thanks for this contribution, @Nyholm! This is great! |
Nice Job @Nyholm |
In order to not be dependent on any version of Guzzle I've implemented PHP-HTTP. This PR will replace #88 and #86. Please try and review carefully.
_Don't merge this PR until ´php-http` is stable._ It is stable now (2016-02-28)
I use Guzzle's psr7 package to properly encode the multipart.
Ping @auro1, @RubenKruiswijk and @farmani any
Question: What is the story behind
CURLOPT_FORBID_REUSE
? I can't find anything about it.Answer: it was used because we wanted to help the load balancers to distribute the load. The load balancers used today are more clever and this setting is not needed.