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

Try to set longer timeouts for Register() in connect #7736

Merged
merged 2 commits into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions class.jetpack-network.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,10 @@ public function do_subsiteregister( $site_id = null ) {
// Figure out what site we are working on
$site_id = ( is_null( $site_id ) ) ? $_GET['site_id'] : $site_id;

// Remote query timeout limit
$timeout = $jp->get_remote_query_timeout_limit();

// better to try (and fail) to set a higher timeout than this system
// supports than to have register fail for more users than it should
$timeout = Jetpack::set_min_time_limit( 60 ) / 2;

// The blog id on WordPress.com of the primary network site
$network_wpcom_blog_id = Jetpack_Options::get_option( 'id' );

Expand Down
24 changes: 20 additions & 4 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -4776,11 +4776,25 @@ public static function delete_secrets( $action, $user_id ) {
* @since 2.6
* @return int
**/
public function get_remote_query_timeout_limit() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're effectively deleting and creating a new method here, we should probably update the @since.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we find a way to deprecate get_remote_query_timeout_limit() to minimize errors if other plugins are using this?

public static function get_max_execution_time() {
$timeout = (int) ini_get( 'max_execution_time' );
if ( ! $timeout ) // Ensure exec time set in php.ini
$timeout = 30;
return intval( $timeout / 2 );
$timeout = 30;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're touching this code, can we add the { and } around the if conditional?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, there are leading spaces before all lines except one in this method. That's a minor nitpick, but should be an easy fix if you go back in.

return $timeout;
}

/**
* Sets a minimum request timeout, and returns the current timeout
*
* @since 5.3
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to update this to 5.4.

**/
public static function set_min_time_limit( $min_timeout ) {
$timeout = self::get_max_execution_time();
if ( $timeout < $min_timeout ) {
$timeout = $min_timeout;
set_time_limit( $timeout );
}
return $timeout;
}


Expand Down Expand Up @@ -4847,7 +4861,9 @@ public static function register() {
return new Jetpack_Error( 'missing_secrets' );
}

$timeout = Jetpack::init()->get_remote_query_timeout_limit();
// better to try (and fail) to set a higher timeout than this system
// supports than to have register fail for more users than it should
$timeout = Jetpack::set_min_time_limit( 60 ) / 2;

$gmt_offset = get_option( 'gmt_offset' );
if ( ! $gmt_offset ) {
Expand Down