Running Artisan Command as a Separate PHP Process in Laravel

In Laravel framework you can create commands and call them from php application.  One command can call another command, and another command, and so on.  But if an exception is thrown in one of the commands in this chain the whole chain breaks.  In order to avoid this problem and run each artisan command as a separate php process (so the exception in one of them does not affect the others), one should use php exec() command together with escapeshellarg() if there are any arguments in the command.

Consider the following example:

 foreach($users as $user) { 
 exec('php '. base_path('artisan email:send ') .escapeshellarg($user['email_address']));
 
}

In this case, if there is an exception in one of the scripts spun up by foreach loop, it will not affect the execution of other scripts.