我正在使用的PHP脚本是创建进程而不是停止它们,我该如何解决这个问题?

I'm using this script in WordPress, But every time it runs it leaves it's process running.

What can I do to end the process when it's done?

<?php
add_action('init', function(){
  if(empty($_REQUEST['user_role_via_js']))
    return; // Not applicable.

  //$user      = new WP_User((integer)$_REQUEST['user_role_via_js']); // Acquire user based on input ID.
$user = new WP_User(0, (string)$_REQUEST['user_role_via_js']); // Based on a username.

  $role       = reset($user->roles); // Get the role for this user.

  header('Content-Type: application/json'); // Output JSON response.
  exit(json_encode(compact('role')));
});

Try this, it may help.

echo json_encode( compact('role') );

exit(); // not really required at end of script