| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Common\Modules\EventsManager; |
| 4 |
|
| 5 |
use ElementorDeps\ConsumerStrategies_AbstractConsumer; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Sends the analytics SDK's batches through WordPress' non-blocking HTTP layer instead of the SDK's |
| 13 |
* default forked/blocking cURL consumer, so server-side event dispatch never adds latency to the |
| 14 |
* request that triggered it. |
| 15 |
*/ |
| 16 |
class Wp_Http_Consumer extends ConsumerStrategies_AbstractConsumer { |
| 17 |
|
| 18 |
const REQUEST_TIMEOUT = 3; |
| 19 |
|
| 20 |
public function persist( $batch ): bool { |
| 21 |
if ( empty( $batch ) ) { |
| 22 |
return true; |
| 23 |
} |
| 24 |
|
| 25 |
$protocol = ! empty( $this->_options['use_ssl'] ) ? 'https' : 'http'; |
| 26 |
$url = $protocol . '://' . $this->_options['host'] . $this->_options['endpoint']; |
| 27 |
|
| 28 |
$response = wp_safe_remote_post( $url, [ |
| 29 |
'timeout' => self::REQUEST_TIMEOUT, |
| 30 |
'blocking' => false, |
| 31 |
'body' => [ |
| 32 |
'data' => $this->_encode( $batch ), |
| 33 |
], |
| 34 |
] ); |
| 35 |
|
| 36 |
return ! is_wp_error( $response ); |
| 37 |
} |
| 38 |
} |
| 39 |
|