Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

PHP Signal Handler

Build Status

Extension uses C signal function (from <signal.h>) to call previously defined callback, if appropriate signal has arrived (i.e SIGUSR1).

When should I use it?

Could be used with php-amqp to print the actual worker/consumer status (ie. message stats, last operation performed etc.)
What's more it is possible to "catch" a unix signal i.e. SIGTERM and then kill the process nicely (program won't stop untill all operations are completed). It is very useful if script operates on sensitive data which cannot be damaged.

Why don't you use pcntl_signal?

If a blocking method (such as AMQPQueue::consume() from php-amqp) is holding the processing thread, then you won't be able to call pcntl_signal_dispatch() and trigger the callbacks registered with pcntl_signal().

Compatibility

Extension will work only if C function signal is available (only on UNIX systems).
PHP versions supported:

  • PHP 7
  • PHP 5.6
  • PHP 5.5
  • PHP 5.4
  • PHP 5.3

Example

<?php

function getInfo($noStatus){
	echo "getInfo called with status $noStatus\n";
}

$r = attach_signal(10, 'getInfo');
while(true){}

?>

Spawn the process:

php your_script_name.php

Kill the first process from the list:

kill -s SIGUSR1 `ps -ef | grep php | head -n1 | awk '{print $2}'`

After that steps you should see:

getInfo called with status 10

About

Singnal handling based on C signal for blocking/nonblocking php scripts

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.