I am trying to send a kill -10 (SIGUSER1) to a process ID by using a button in a webpage, I have tried different ways to send the signal while passing the PHP variable (which holds the PID) to shell. Below is what I have:
$next = posix_kill($pid3, 10);
Right now, this is giving me the below error:
PHP Warning: posix_kill() expects parameter 1 to be long,
string given in /var/www/parse2.php on line 15
Please advise
Just try this:
$next = posix_kill((long)$pid3, 10);
Intval returns an int so the warning won't go away, but it will probably work
So since you seem to have a problem still better would be like suggested elswhere:
$next = posix_kill(intval($pid3), 10);
If that doesn't work I'd suggest to show us the php version you use.
Unless you have a space that comes with it, then try:
$next = posix_kill(intval(trim($pid3)), 10);
update:
So now you got it working, you need to trap the signal and make it do something, you need to attach a callback function, since I don't know the rest of your code. You need something like this :
pcntl_signal(SIGUSR1, "sig_handler");
Then do something on that signal:
function sig_handler($sig) {
switch($sig) {
case SIGUSR1:
// logtrace(1,"received USR1 signal.");
break;
...
I just think about 1 thing, I assume that the process we are sending a signal is a PHP script. Otherwise I think you got it working but isn't doing a whole lot (yet)
most php functions will try to coerce their arguments into the appropriate data type if its possible. its extremely common for php functions to automatically convert strings into numeric types like int or float, if possible.
But, some just aren't written that way, and you need to supply the data type specified in the manual.
"long" is a numeric type, so just cast to integer. This assumes $pid3 is a numeric string, so that the cast results in something sensible.
$next = posix_kill((int) $pid3, 10);
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