0

I'm having an Issue with the php OCI8 module.

I have a php worker handling some stuff and I realized once there is an open oci connection the php script ignores any interruption signal:

<?php

$db = oci_connect(...);

while (true) {
    // do something
}

there is no way to gracefully stop this script. At least that I know of. I have tried using pcntl_signal() to create my custom signal handler, won't work though. Right now i need to kill the process manually.

Anyone have this issue or a way to handle SIGINT with oci?

cheers!

Friedrich Roell
  • 437
  • 1
  • 5
  • 14
  • possible duplicate: http://stackoverflow.com/questions/17124881/oracle-proc-oci-install-handlers-for-sigsegv-sigabrt-and-friends-why-and-how – ibre5041 Jan 24 '17 at 07:59

1 Answers1

0

You can try this code:

declare(ticks=1); //mandatory
oci_connect(...);

pcntl_signal(SIGINT, 'sig_handler'); //set handler for signal

$i = 0;
while(true) {
    echo $i;
    $i++;
}

//will handle the ctrl+c. Put whatever you want to do
function sig_handler() {
    echo "DIE DIE DIE!";
    die();
}

More here: http://php.net/manual/en/function.pcntl-signal.php

Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
  • 1
    unfortunately, as I mentioned, custom signal handlers dont work either :/ – Friedrich Roell Jan 24 '17 at 08:33
  • I did run this exactly code, connecting with a Oracle 11g database, and it works. Have you tried this exactly code? – Felippe Duarte Jan 24 '17 at 10:49
  • IMHO it it better to set env. variable DIAG_SIGHANDLER_ENABLED=FALSE before starting PHP. – ibre5041 Jan 24 '17 at 14:18
  • @FelippeDuarte ok ... after running EXACTLY the code you provided, it actually worked. The difference: I had an empty while loop, while yours had an echo in it. anyone know how that made it work? – Friedrich Roell Jan 30 '17 at 17:54
  • Work here with `while(true) {}`. Could you update your question with the code that you are actually using? (omitting sensitive information) – Felippe Duarte Jan 30 '17 at 18:07