I am using pcntl_fork to start a child process to send an email via SMTP.
The child process uses the PEAR Mail package to send the email, but the trouble is if the remote server doesn't respond the process just runs forever waiting for a response, regardless of any time limit that is set in php.ini.
To get around this I'm using pcntl_alarm function to trigger a function after 30 seconds that kills the child process if it's still running.
function handlesig($sig) {
global $pid,$node,$resend;
posix_kill($pid,SIGKILL);
mysql_query("insert into log (event) values ('Timed out!')");
}
When I kill the child process though I'm left with a defunct process on the system.
Is there a different signal I should use that will still force the child process to die without waiting for the connection (because the connection will never finish) and avoid a build up of defunct processes?