Search code examples
phpprocessprocess-managementpid

Kill Running PHP Script via Process ID?


I make lots of GET requests to several PHP scripts via AJAX. I want to ask for implementation advice on how to kill a PHP script that is currently running (in the background).

Is there some way to get the PHP scripts process ID when it runs and then I can probably kill that process via shell/cmd etc?

Is there a better way?


Solution

  • Whether PHP is a process of its own at all will depend on how PHP and web server are configured. But even when it is, it is going to be awfully hard to catch the correct PHP process to kill.

    If you know inside your PHP script that this is the process that needs killing, you may be able to use getmypid() or find something in the User Contributed Notes there.

    I still don't entirely understand the situation. Why do you need to kill them at all?