I am writing a policy server in PHP. I am confused by some of postfix behavior.
I designed the PHP service in this manner;

/usr/libexec/postfix/per-user-policy:
#!/usr/bin/php
<?php
...code...
?>


master.cf:
userpolicy unix - n n - 0 spawn user=mail argv=/usr/libexec/postfix/per-user-policy


main.cf:
userpolicy_time_limit = 3600
smtpd_recipient_restrictions =
    check_policy_service unix:private/userpolicy


As of now the policy script writes values supplied by postfix to a log file and returns the expected action=dunno and empty line. I designed the PHP to run in a loop with no time outs for it to be available for multiple request. My understanding of SMTPD_POLICY_README is postfix will reuse the policy service multiple times.

"Unless there was an error, the server must not close the connection, so that the same connection can be used multiple times."
Did i take this too literal?

My postfix setup it is not reusing connections. Every email spawns a new instance. And since the script waits for the next request it doesn't self terminate causing the system to fill up with zombie instances of the script.

I thought the behavior should be postfix spawns a policy service, uses that same connection for multiple emails until it hits the limit, kills the policy script and spawns a new one as a type of memory management. I tried having my script listen for any SIG??? from postfix to shut it down gracefully, but i never detected any.

What is the correct way? Is there something wrong in my config causing a new spawn per email or is that how it is supposed to work? Is postfix supposed to terminate the script? Or what is the method im supposed to use so my script knows when to self terminate? Or should the script be designed as a one time use and always terminate after sending an action= ?

Reply via email to