Jump to content

Recommended Posts

Hi guys,

 

  Like the title says, for some reason SIGINT is not being caught and ending the process when it is sent.

<?php

 define('logdir', '/var/www/html/Project2');

 $pid = getmypid();
 function catch_sigint($sig_num) {

   print('got a signal sigint\n');
   flush(STDOUT);

     pcntl_signal(SIGINT, "catch_sigint");
     posix_kill($pid, SIGINT);
     exit(1);

 }

  if((count($argc) < 1 )||(count($argc) >=2)) {
    print("usage: webserver idcode");
    exit(1);
  }

  pcntl_signal(SIGINT, "catch_sigint");

  while(1) { print "running"; sleep(3); }

?>

If it's any insight, I had an interesting problem with getting the pid - I originally tried posix_getpid() but it gave an error saying that it was undefined though I'm running this on a Linux machine. The webserver env. is Apache. Thanks for any and all help!

 

Link to comment
https://forums.phpfreaks.com/topic/282895-sigint-not-being-caught/
Share on other sites

As of PHP 4.3.0 PCNTL uses ticks as the signal handle callback mechanism, which is much faster than the previous mechanism. This change follows the same semantics as using "user ticks". You must use the declare() statement to specify the locations in your program where callbacks are allowed to occur for the signal handler to function properly (as used in the above example).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.