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

Transfer & connect timeouts, in seconds & milliseconds #97

Merged
merged 3 commits into from
Jan 24, 2014
Merged

Transfer & connect timeouts, in seconds & milliseconds #97

merged 3 commits into from
Jan 24, 2014

Conversation

ozh
Copy link
Collaborator

@ozh ozh commented Jan 23, 2014

This PR supersedes #58 & #83

  • You can now specify timeout and connect_timeout
  • milliseconds are supported, in a backward compatible way (eg 'timeout' => 3 or 'timeout' => 3.55)

I've added a cool example also.

I didn't add tests, as that would just slow down things, but it's possible with the same URL used in the example

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) when pulling 0c6a797 on ozh:timeouts into 541e6d0 on rmccue:master.

@ozh
Copy link
Collaborator Author

ozh commented Jan 23, 2014

A few more or less related comments:

  • you should move HHVM into another branch's .travis.yml : this way the whole project wouldn't get a "Build: Failing" badge just because of it
  • I think this PR would justify a neat 1.6.1 tag

@@ -198,7 +198,10 @@ public function request($url, $headers = array(), $data = array(), $options = ar
$options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers));
return '';
}
stream_set_timeout($fp, $options['timeout']);

$timeout_sec = (int) floor( $options['timeout'] );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks wrong here?

@rmccue
Copy link
Collaborator

rmccue commented Jan 24, 2014

Thanks! 🎆

I didn't add tests, as that would just slow down things, but it's possible with the same URL used in the example

Going to need tests :)

you should move HHVM into another branch's .travis.yml : this way the whole project wouldn't get a "Build: Failing" badge just because of it

I meant to fix HHVM support properly but didn't get around to it. Whoops. (See: #93)

I think this PR would justify a neat 1.6.1 tag

1.6.x is bug fixes only, but this is certainly good for 1.7.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 247a225 on ozh:timeouts into 541e6d0 on rmccue:master.

@ozh
Copy link
Collaborator Author

ozh commented Jan 24, 2014

Release the Kraken ! Or, well, just 1.7, that'd be fine too.

stream_set_timeout($fp, $options['timeout']);

$timeout_sec = (int) floor( $options['timeout'] );
$timeout_msec = $timeout_sec == $options['timeout'] ? 0 : 1000000 * $options['timeout'] % 1000000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this number represent? We should move it to a class constant instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a million to compute the microsecond part of the timeout...

$options['timeout']  = 2.15;
$timeout_sec = (int) floor( $options['timeout'] );
$timeout_msec = $timeout_sec == $options['timeout'] ? 0 : 1000000 * $options['timeout'] % 1000000;
var_dump( $timeout_sec, $timeout_msec ); // "int 2" and "int 150000"

Not sure there's a point in using a class const, I think a comment would be better then :) I'm always reluctant to add comments in Request, as there is very few of them in here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part I try and make it self-explanatory, but the issue here is that it's easy to miss a 0. A class constant ensures that there's no error usually. (Something like SECOND_IN_MICROSECONDS would work well here, IMO)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay -- const in Requests.php or, since it's only used in fsockopen, in Transport/fsockopen.php ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class constant for Requests_Transport_fsockopen, since it's only used there. :)

@rmccue
Copy link
Collaborator

rmccue commented Jan 24, 2014

Thanks! I'll merge once the small coding standards bits are fixed. 🍝

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling b025d3c on ozh:timeouts into 541e6d0 on rmccue:master.

@rmccue
Copy link
Collaborator

rmccue commented Jan 24, 2014

Thanks for that!

rmccue added a commit that referenced this pull request Jan 24, 2014
Transfer & connect timeouts, in seconds & milliseconds
@rmccue rmccue merged commit 628533e into WordPress:master Jan 24, 2014
@ozh ozh deleted the timeouts branch January 24, 2014 15:43
@ozh
Copy link
Collaborator Author

ozh commented Jan 24, 2014

Neat, thanks a lot. I needed this for the next iteration of YOURLS. (By the way, if you haven't seen it already, I did some pimping for Requests on YOURLS blog recently)

Next on your agenda: hhvm tests in their own branch, and tagging + release :)

@rmccue rmccue mentioned this pull request Jan 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants