Skip to content

Commit

Permalink
Consolidate set-or-default timeout code in one function
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityrail committed Sep 6, 2017
1 parent 9dea8d7 commit 2c56fe0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
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() {
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;
return $timeout;
}

/**
* Sets a minimum request timeout, and returns the current timeout
*
* @since 5.3
**/
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

0 comments on commit 2c56fe0

Please sign in to comment.