host = $options['host']; $this->endpoint = $options['endpoint']; $this->protocol = isset( $options['use_ssl'] ) && ( true === $options['use_ssl'] ) ? 'https' : 'http'; } /** * Send post request to the given host/endpoint using WordPress's HTTP API * * @param mixed[] $batch Batch of data to send to mixpanel. * * @return bool */ public function persist( $batch ) { if ( count( $batch ) <= 0 ) { return true; } $url = $this->protocol . '://' . $this->host . $this->endpoint; $data = 'data=' . $this->_encode( $batch ); // Non-blocking still waits up to the timeout, it only discards the response: // the timeout is what bounds the cost of a degraded endpoint. $response = wp_remote_post( $url, [ 'timeout' => self::REQUEST_TIMEOUT, 'blocking' => false, 'body' => $data, ] ); if ( is_wp_error( $response ) ) { $this->_handleError( $response->get_error_code(), $response->get_error_message() ); } /* * Report the batch as consumed even on failure. Returning false would make the * producer re-queue it and retry the flush up to 10 times at shutdown, once per * producer, multiplying the cost of an unreachable endpoint. * * @see \Imagify_WPMedia_Producers_MixpanelBaseProducer::__destruct() */ return true; } }