| @@ -14,12 +14,12 @@ | ||
| 14 | 14 | use WCPOS\WooCommercePOS\Services\Pos_Order_Audit; |
| 15 | 15 | use WCPOS\WooCommercePOS\Services\Settings; |
| 16 | 16 | use WCPOS\WooCommercePOS\Sync\Meta_Normalizer; |
| 17 | 17 | use WCPOS\WooCommercePOS\Sync\Pos_Uuid; |
| 18 | +use WCPOS\WooCommercePOS\Sync\Response_Telemetry; | |
| 18 | 19 | use WP_Error; |
| 19 | 20 | use WP_REST_Request; |
| 20 | 21 | use WP_REST_Response; |
| 21 | -use Exception; | |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Shared helpers for all WCPOS REST API controllers. |
| 25 | 25 | */ |
| @@ -461,30 +461,14 @@ | ||
| 461 | 461 | |
| 462 | 462 | /** |
| 463 | 463 | * Get server load average. |
| 464 | 464 | * |
| 465 | + * Same source as the v2 lane's `X-Server-Load`. The former Windows branch | |
| 466 | + * tested `stristr( PHP_OS, 'win' )`, which also matches `Darwin`, so every | |
| 467 | + * macOS host shelled out to `wmic` on each bulk-ID request. | |
| 468 | + * | |
| 465 | 469 | * @return array The load average. |
| 466 | 470 | */ |
| 467 | 471 | public function get_server_load() { |
| 468 | - try { | |
| 469 | - if ( stristr( PHP_OS, 'win' ) ) { | |
| 470 | - // Use WMIC to get load percentage from Windows. | |
| 471 | - $load = @shell_exec( 'wmic cpu get loadpercentage /all' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 472 | - if ( $load ) { | |
| 473 | - $load = explode( "\n", $load ); | |
| 474 | - if ( isset( $load[1] ) ) { | |
| 475 | - $load = intval( $load[1] ); | |
| 476 | - return array( $load, $load, $load ); // Mimic the array structure of sys_getloadavg(). | |
| 477 | - } | |
| 478 | - } | |
| 479 | - } elseif ( function_exists( 'sys_getloadavg' ) ) { | |
| 480 | - return sys_getloadavg(); | |
| 481 | - } | |
| 482 | - } catch ( Exception $e ) { | |
| 483 | - // Log the error for debugging purposes. | |
| 484 | - Logger::log( 'Error getting server load: ' . $e->getMessage() ); | |
| 485 | - } | |
| 486 | - | |
| 487 | - // Fallback if no method is available or an error occurs. | |
| 488 | - return array( 0, 0, 0 ); | |
| 472 | + return Response_Telemetry::server_load(); | |
| 489 | 473 | } |
| 490 | 474 | } |