Create plugin that works in background

You need to use WP Background Processing which fire off non-blocking asynchronous requests.

WooCommerce also use this for background processing. Check the file /includes/libraries/wp-background-process.php