I am facing one issue regarding killing a Linux process from my php code.
I am running a Scrapy tool from my php code using the proc_open()
function in the background.
It works fine, but now I want to kill this process using its process id.
To do that I'm using exec("sudo kill -9 $pid");
where $pid
is the process id which I'm getting from my php code.
The problem is this process is running on behalf of the apache user. I thought there might be some permissions issue, so I added apache user to the sudoers file like this apache ALL=(ALL) NOPASSWD:ALL
but I'm still not able to kill it. Somehow, the same kill command works from my putty console.
My code is on an Amazon EC2 instance.
My question is, how can I kill that process identified by a pid from php?
Never, ever, give apache sudo
permissions!
Use exec("kill -9 $pid");
- your apache process started it, it can kill it :)
Try posix_kill
:
bool posix_kill ( int $pid , int $sig )
Send the signal sig to the process with the process identifier pid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With