public/wordpress/wp-content/plugins/backupbuddy/classes/backup.php
/*	cron_next_step()
	 *
	 * NOTE: fileoptions ($this->_backup) should be closed prior to running this. Not doing so could result in race condition issues.
	 *	
	 *	Schedule the next step into the cron. Defaults to scheduling to happen _NOW_. Automatically opens a loopback to trigger cron in another process by default.
	 *	
	 *	@param		boolean		$spawn_cron			Whether or not to to spawn a loopback to run the cron. If using an offset this most likely should be false. Default: true
	 *	@param		int			$future_offset		Seconds in the future for this process to run. Most likely set $spawn_cron false if using an offset. Default: -155 to force to top.
	 *	@param		string		$next_step_title	Optional text title/function name/whatever of the next step to run. Useful for troubleshooting. Status logged.
	 *	@return		null
	 */
cron_next_step()
NOTE: fileoptions ($this->_backup) should be closed prior to running this. Not doing so could result in race condition issues.

Schedule the next step into the cron. Defaults to scheduling to happen _NOW_. Automatically opens a loopback to trigger cron in another process by default.

@param          boolean         $spawn_cron                     Whether or not to to spawn a loopback to run the cron. If using an offset this most likely should be false. Default: true
@param          int                     $future_offset          Seconds in the future for this process to run. Most likely set $spawn_cron false if using an offset. Default: -155 to force to top.
@param          string          $next_step_title        Optional text title/function name/whatever of the next step to run. Useful for troubleshooting. Status logged.
@return         null
cron_next_step () NOTE : fileoptions ( $this - > _backup ) should be closed prior to running this . Not doing so could result in race condition issues . Schedule the next step into the cron . Defaults to scheduling to happen _NOW_ . Automatically opens a loopback to trigger cron in another process by default . @param boolean $spawn_cron Whether or not to to spawn a loopback to run the cron . If using an offset this most likely should be false . Default : true @param int $future_offset Seconds in the future for this process to run . Most likely set $spawn_cron false if using an offset . Default : - 155 to force to top . @param string $next_step_title Optional text title / function name / whatever of the next step to run . Useful for troubleshooting . Status logged . @return null
function cron_next_step( $serial, $spawn_cron = true, $future_offset = -155, $next_step_title = '' ) {
		if ( '' != $this->_backup ) {
			pb_backupbuddy::status( 'warnings', 'Warning #438943984983. This warning may be okay and ignored. $this->_backup still appears to be set. Still a fileoptions object? May result in race condition issues if fileoptions still open and/or locked. Set = empty string to verify it shuts down properly prior to calling this function.' );
		}
		if ( '1' == pb_backupbuddy::$options['use_internal_cron'] ) {
			if ( $future_offset > 0 ) { 
				if ( $future_offset > backupbuddy_core::adjustedMaxExecutionTime() ) {
					$future_offset = 5; 
				}
				sleep( $future_offset );
			}
			$cron_url = site_url();
			$args = array(
						'backupbuddy_cron_action' => 'process_backup',
						'backupbuddy_serial' => $serial,
						'backupbuddy_time' => time(),
						'backupbuddy_key' => pb_backupbuddy::$options['log_serial']
					);
			pb_backupbuddy::status( 'details', 'Attempting to bypass WordPress cron and use internal cron system calling `' . $cron_url . '`. Args: `' . print_r( $args, true ) . '`.' );
			pb_backupbuddy::flush();
			$response = wp_remote_post( $cron_url, array(
					'method' => 'POST',
					'timeout' => backupbuddy_core::adjustedMaxExecutionTime(),
					'redirection' => 3,
					'httpversion' => '1.0',
					'blocking' => false,
					'headers' => array(),
					'body' => $args,
					'cookies' => array()
				)
			);
			pb_backupbuddy::status( 'details', 'Cron response: `' . print_r( $response, true ) . '`.' );
			return;
		}
		if ( '1' == pb_backupbuddy::$options['skip_spawn_cron_call'] ) {
			pb_backupbuddy::status( 'details', 'Advanced option to skip call to spawn cron enabled. Setting to skip spawn_cron() call.' );
			$spawn_cron = false;
		}
		pb_backupbuddy::status( 'details', 'Scheduling Cron for `' . $serial . '`.' );
		@include_once( pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php' );
		if ( class_exists( 'pluginbuddy_wpdbutils' ) ) {
			global $wpdb;
			$dbhelper = new pluginbuddy_wpdbutils( $wpdb );
			if ( ! $dbhelper->kick() ) {
				pb_backupbuddy::status( 'error', __('Database Server has gone away, unable to schedule next backup step. The backup cannot continue. This is most often caused by mysql running out of memory or timing out far too early. Please contact your host.', 'it-l10n-backupbuddy' ) );
				pb_backupbuddy::status( 'haltScript', '' ); 
				return false;
			}
		} else {
			pb_backupbuddy::status( 'details', __('Database Server connection status unverified.', 'it-l10n-backupbuddy' ) );
		}
		$cron_time = ( time() + $future_offset );
		$cron_args = array( $serial );
		pb_backupbuddy::status( 'details', 'Scheduling next step to run at `' . $cron_time . '` (localized time: ' . pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $cron_time ) ) . '), pushed to the top, with cron tag `backupbuddy_cron` to run method `process_backup` and serial arguments `' . implode( ',', $cron_args ) . '`.' );
		$schedule_result = backupbuddy_core::schedule_single_event( $cron_time, 'process_backup', $cron_args, $reschedule = 0 );
		if ( $schedule_result === false ) {
			pb_backupbuddy::status( 'error', 'Unable to schedule next cron step. Verify that another plugin is not preventing / conflicting.' );
		} else {
			pb_backupbuddy::status( 'details', 'Next step scheduled.' );
			pb_backupbuddy::status( 'startAction', 'cronPass' );
			pb_backupbuddy::status( 'cronParams', base64_encode( json_encode( array( 'time' => $cron_time, 'tag' => 'backupbuddy_cron', 'method' => 'process_backup', 'args' => $cron_args ) ) ) );
		}
		update_option( '_transient_doing_cron', 0 ); 
		if ( $spawn_cron === true ) {
			pb_backupbuddy::status( 'details', 'Calling spawn_cron().' );
			spawn_cron( time() + 150 ); 
		} else {
			pb_backupbuddy::status( 'details', 'Not calling spawn_cron().' );
		}
		$next_step_note = '';
		if ( '' != $next_step_title ) {
			$next_step_note = ' (' . $next_step_title . ' expected)';
		}
		pb_backupbuddy::status( 'details', 'About to run next step' . $next_step_note . '. If the backup does not proceed within 15 seconds then something is interfering with the WordPress CRON system such as: server loopback issues, caching plugins, scheduling plugins, another plugin using all available cron time, or another BackupBuddy process in progress (file transfers, other backups, Stash Live backup) taking up all cron time. Try disabling other plugins to see if it resolves issue.  Check the Server Information page cron section to see if the next BackupBuddy step is scheduled to run. Enable "Classic" backup mode on the "Settings" page to rule out non-cron issues. Additionally you may verify no other backup processes are trying to run at the same time by verifying there is not an existing backup process listed in the cron hogging the cron process.' );
		return;
	}
function cron_next_step ( $ serial , $ spawn_cron = true , $ future_offset = - 155 , $ next_step_title = '' ) { if ( '' != $ this -> _backup ) { pb_backupbuddy :: status ( 'warnings' , 'Warning #438943984983. This warning may be okay and ignored. $this->_backup still appears to be set. Still a fileoptions object? May result in race condition issues if fileoptions still open and/or locked. Set = empty string to verify it shuts down properly prior to calling this function.' ) ; } if ( '1' == pb_backupbuddy :: $ options [ 'use_internal_cron' ] ) { if ( $ future_offset > 0 ) { if ( $ future_offset > backupbuddy_core :: adjustedMaxExecutionTime ( ) ) { $ future_offset = 5 ; } sleep ( $ future_offset ) ; } $ cron_url = site_url ( ) ; $ args = array ( 'backupbuddy_cron_action' => 'process_backup' , 'backupbuddy_serial' => $ serial , 'backupbuddy_time' => time ( ) , 'backupbuddy_key' => pb_backupbuddy :: $ options [ 'log_serial' ] ) ; pb_backupbuddy :: status ( 'details' , 'Attempting to bypass WordPress cron and use internal cron system calling `' . $ cron_url . '`. Args: `' . print_r ( $ args , true ) . '`.' ) ; pb_backupbuddy :: flush ( ) ; $ response = wp_remote_post ( $ cron_url , array ( 'method' => 'POST' , 'timeout' => backupbuddy_core :: adjustedMaxExecutionTime ( ) , 'redirection' => 3 , 'httpversion' => '1.0' , 'blocking' => false , 'headers' => array ( ) , 'body' => $ args , 'cookies' => array ( ) ) ) ; pb_backupbuddy :: status ( 'details' , 'Cron response: `' . print_r ( $ response , true ) . '`.' ) ; return ; } if ( '1' == pb_backupbuddy :: $ options [ 'skip_spawn_cron_call' ] ) { pb_backupbuddy :: status ( 'details' , 'Advanced option to skip call to spawn cron enabled. Setting to skip spawn_cron() call.' ) ; $ spawn_cron = false ; } pb_backupbuddy :: status ( 'details' , 'Scheduling Cron for `' . $ serial . '`.' ) ; @ include_once ( pb_backupbuddy :: plugin_path ( ) . '/lib/wpdbutils/wpdbutils.php' ) ; if ( class_exists ( 'pluginbuddy_wpdbutils' ) ) { global $ wpdb ; $ dbhelper = new pluginbuddy_wpdbutils ( $ wpdb ) ; if ( ! $ dbhelper -> kick ( ) ) { pb_backupbuddy :: status ( 'error' , __ ( 'Database Server has gone away, unable to schedule next backup step. The backup cannot continue. This is most often caused by mysql running out of memory or timing out far too early. Please contact your host.' , 'it-l10n-backupbuddy' ) ) ; pb_backupbuddy :: status ( 'haltScript' , '' ) ; return false ; } } else { pb_backupbuddy :: status ( 'details' , __ ( 'Database Server connection status unverified.' , 'it-l10n-backupbuddy' ) ) ; } $ cron_time = ( time ( ) + $ future_offset ) ; $ cron_args = array ( $ serial ) ; pb_backupbuddy :: status ( 'details' , 'Scheduling next step to run at `' . $ cron_time . '` (localized time: ' . pb_backupbuddy :: $ format -> date ( pb_backupbuddy :: $ format -> localize_time ( $ cron_time ) ) . '), pushed to the top, with cron tag `backupbuddy_cron` to run method `process_backup` and serial arguments `' . implode ( ',' , $ cron_args ) . '`.' ) ; $ schedule_result = backupbuddy_core :: schedule_single_event ( $ cron_time , 'process_backup' , $ cron_args , $ reschedule = 0 ) ; if ( $ schedule_result === false ) { pb_backupbuddy :: status ( 'error' , 'Unable to schedule next cron step. Verify that another plugin is not preventing / conflicting.' ) ; } else { pb_backupbuddy :: status ( 'details' , 'Next step scheduled.' ) ; pb_backupbuddy :: status ( 'startAction' , 'cronPass' ) ; pb_backupbuddy :: status ( 'cronParams' , base64_encode ( json_encode ( array ( 'time' => $ cron_time , 'tag' => 'backupbuddy_cron' , 'method' => 'process_backup' , 'args' => $ cron_args ) ) ) ) ; } update_option ( '_transient_doing_cron' , 0 ) ; if ( $ spawn_cron === true ) { pb_backupbuddy :: status ( 'details' , 'Calling spawn_cron().' ) ; spawn_cron ( time ( ) + 150 ) ; } else { pb_backupbuddy :: status ( 'details' , 'Not calling spawn_cron().' ) ; } $ next_step_note = '' ; if ( '' != $ next_step_title ) { $ next_step_note = ' (' . $ next_step_title . ' expected)' ; } pb_backupbuddy :: status ( 'details' , 'About to run next step' . $ next_step_note . '. If the backup does not proceed within 15 seconds then something is interfering with the WordPress CRON system such as: server loopback issues, caching plugins, scheduling plugins, another plugin using all available cron time, or another BackupBuddy process in progress (file transfers, other backups, Stash Live backup) taking up all cron time. Try disabling other plugins to see if it resolves issue.  Check the Server Information page cron section to see if the next BackupBuddy step is scheduled to run. Enable "Classic" backup mode on the "Settings" page to rule out non-cron issues. Additionally you may verify no other backup processes are trying to run at the same time by verifying there is not an existing backup process listed in the cron hogging the cron process.' ) ; return ; }
cron_next_step()
 NOTE: fileoptions ($this->_backup) should be closed prior to running this.
cron_next_step () NOTE : fileoptions ( $this - > _backup ) should be closed prior to running this .
// Internal cron (optional; disabled by default). // Delay requsted. // If huge, try 5 sec. // Need to make sure the database connection is active. Sometimes it goes away during long bouts doing other things -- sigh. // This is not essential so use include and not require (suppress any warning) // Halt JS on page. // Schedule event. // Prevent cron-blocking for next item. // Spawn cron. // Adds > 60 seconds to get around once per minute cron running limit.