I found a chunk of code that I haven’t seen before:
declare(ticks = 1);
pcntl_signal(SIGINT, array($this, "catchSignal"));
pcntl_signal(SIGTERM, array($this, "catchSignal"));
I looked up the function in the PHP documentation, but I still don’t understand what this is used for. Please help me understand what this is used for and some examples of where this should be implemented.
The declare statement states to check for events every “tick”. A “tick” being roughly equal to a line of code. This is used in command line PHP scripts so you can catch interrupts and shutdown the script gracefully instead of just killing it.
The
array($this, "catchSignal")in thepcntl_signalfunction is an odd work around (in my opinion) to support “objects” as parameters. Normally you would just do$this->catchSignal(), but PHP doesn’t accept class objects as parameters in this case. Thus the “array” syntax.Basically, if the script is issued an Interrupt or Termination signal, call the
$this->catchSignal()function before shutting down.