You can kill the php process by identifying the process ids. but that you have to execute directly from terminal by logged in as a root user. Its a bad approach to give privilege for the www-data(php user) to kill the process.
Best approach is, Inside the loop you have to check any flag stored in database in order to proceed, otherwise exit. So you can easily manage those database flag easily through code.