Cannot Disable User Programmatically With user_cancel() I want to disable user using user_cancel method.

//A function that disables a user.
function myid_admin_disable_user(){
    try{    
        $edit = array(
            'user_cancel_notify' =&gt; true,
        );

        $method = 'user_cancel_block';  
        //5 is the user id of the account I want to disable.
        user_cancel($edit, 5, $method);     
        echo true;
    }catch(Exception $e){
        echo false;
    }
}


After running the function above, I can still use the account which is supposed to be disabled. Why? Whats wrong in my code above?
Per the docs in user_cancel():


  Since the user cancellation process needs to be run in a batch, either
  Form API will invoke it, or batch_process() needs to be invoked after
  calling this function and should define the path to redirect to.


You need to invoke the batch API in order to trigger the result. 

// Set the notify and cancel type options.    
user_cancel(array(
  'user_cancel_notify' =&gt; TRUE,
  'user_cancel_method' =&gt; 'user_cancel_delete',
), 5, 'user_cancel_delete');

// Invoke the Batch API, disable drupal_goto(), and execute.
$batch = &amp;batch_get();
$batch['progressive'] = FALSE;
batch_process();