You appear to be a bot. Output may be restricted
Description
Sends data to WordPress.com via an XMLRPC request.
Usage
$mixed|WP_Error = Actions::send_data( $data, $codec_name, $sent_timestamp, $queue_id, $checkout_duration, $preprocess_duration, $queue_size, $buffer_id );
Parameters
- $data
- ( object ) required – Data relating to a sync action.
- $codec_name
- ( string ) required – The name of the codec that encodes the data.
- $sent_timestamp
- ( float ) required – Current server time so we can compensate for clock differences.
- $queue_id
- ( string ) required – The queue the action belongs to, sync or full_sync.
- $checkout_duration
- ( float ) required – Time spent retrieving queue items from the DB.
- $preprocess_duration
- ( float ) required – Time spent converting queue items into data to send.
- $queue_size
- ( int ) optional – The size of the sync queue at the time of processing.
- $buffer_id
- ( string ) optional – The ID of the Queue buffer checked out for processing.
Returns
mixed|WP_Error The result of the sending request.
Source
File name: jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-actions.php
Lines:
1 to 100 of 114
public static function send_data( $data, $codec_name, $sent_timestamp, $queue_id, $checkout_duration, $preprocess_duration, $queue_size = null, $buffer_id = null ) { $query_args = array( 'sync' => '1', // Add an extra parameter to the URL so we can tell it's a sync action. 'codec' => $codec_name, 'timestamp' => $sent_timestamp, 'queue' => $queue_id, 'cd' => sprintf( '%.4f', $checkout_duration ), 'pd' => sprintf( '%.4f', $preprocess_duration ), 'queue_size' => $queue_size, 'buffer_id' => $buffer_id, // TODO this will be extended in the future. Might be good to extract in a separate method to support future entries too. 'sync_flow_type' => Settings::is_dedicated_sync_enabled() ? 'dedicated' : 'default', ); $query_args['timeout'] = Settings::is_doing_cron() ? 30 : 20; if ( 'immediate-send' === $queue_id ) { $query_args['timeout'] = 30; } /** * Filters query parameters appended to the Sync request URL sent to WordPress.com. * * @since 1.6.3 * @since-jetpack 4.7.0 * * @param array $query_args associative array of query parameters. */ $query_args = apply_filters( 'jetpack_sync_send_data_query_args', $query_args ); $connection = new Jetpack_Connection(); $url = add_query_arg( $query_args, $connection->xmlrpc_api_url() ); // If we're currently updating to Jetpack 7.7, the IXR client may be missing briefly // because since 7.7 it's being autoloaded with Composer. if ( ! class_exists( '\\Jetpack_IXR_Client' ) ) { return new WP_Error( 'ixr_client_missing', esc_html__( 'Sync has been aborted because the IXR client is missing.', 'jetpack-sync' ) ); } $rpc = new \Jetpack_IXR_Client( array( 'url' => $url, 'timeout' => $query_args['timeout'], ) ); $result = $rpc->query( 'jetpack.syncActions', $data ); // Adhere to Retry-After headers. $retry_after = $rpc->get_response_header( 'Retry-After' ); if ( false !== $retry_after ) { if ( (int) $retry_after > 0 ) { update_option( self::RETRY_AFTER_PREFIX . $queue_id, microtime( true ) + (int) $retry_after, false ); } else { // if unexpected value default to 3 minutes. update_option( self::RETRY_AFTER_PREFIX . $queue_id, microtime( true ) + 180, false ); } } // Enable/Disable Dedicated Sync flow via response headers. $dedicated_sync_header = $rpc->get_response_header( 'Jetpack-Dedicated-Sync' ); if ( false !== $dedicated_sync_header ) { $dedicated_sync_enabled = 'on' === $dedicated_sync_header ? 1 : 0; Settings::update_settings( array( 'dedicated_sync_enabled' => $dedicated_sync_enabled, ) ); } if ( ! $result ) { if ( false === $retry_after ) { // We received a non standard response from WP.com, lets backoff from sending requests for 1 minute. update_option( self::RETRY_AFTER_PREFIX . $queue_id, microtime( true ) + 60, false ); } // Record Sync Errors. $error_log = get_option( self::ERROR_LOG_PREFIX . $queue_id, array() ); if ( ! is_array( $error_log ) ) { $error_log = array(); } // Trim existing array to last 4 entries. if ( 5 <= count( $error_log ) ) { $error_log = array_slice( $error_log, -4, null, true ); } // Add new error indexed to time. $error_log[ (string) microtime( true ) ] = $rpc->get_jetpack_error(); // Update the error log. update_option( self::ERROR_LOG_PREFIX . $queue_id, $error_log ); // return request error. return $rpc->get_jetpack_error(); } $response = $rpc->getResponse(); // Check if WordPress.com IDC mitigation blocked the sync request.