Answer the question
In order to leave comments, you need to log in
How can I execute the checkmail.php script not by cron, but immediately after receiving the letter by the nginx server?
How can I execute the checkmail.php script not by cron, but immediately after receiving the letter by the nginx server?
Everything works on cron, but he can check this script no more than once every 2 minutes. Is it possible to launch a php script immediately after receiving an email? Does the nginx server do something to hook on to?
Server on Debian. cPanel enabled.
Answer the question
In order to leave comments, you need to log in
If the email is put into a file, then you can monitor the mail directory with inotify (linux-only?).
On Debian and Ubuntu look at the incron, iwatch packages.
Option number 2 - monitor nginx'a logs and run a command when catching an event:
(
date +'%Y.%m.%d %H:%M:%S -- Started...'
while : ; do
tail -F /var/log/nginx/access.log |
grep --line-buffered -i -- "smtp" |
while read line; do
date +"%Y.%m.%d %H:%M:%S -- $line"
php -f /path/to/checkmail.php
done
date +'%Y.%m.%d %H:%M:%S -- Restarted...'
sleep 30
done
) > /var/log/checkmail.log 2>&1 &
I do not think that nginx can be at least a minimally complete SMTP server.
As far as I understood, nginx is only a proxy authorizer.
With exim, I did this:
see habrahabr.ru/post/164661/
Yes, and more. If cpanel, then there it is called cpanel mail piping (depends on the mail server used)
In Cpanel there is an option MailForwarding, there is an advanced button and turn on piping, i.e. specify a link to a previously saved script with something like this:
#!/usr/bin/php -q
<?php
require_once "your_script.php";
?> The
first line must be straight from the beginning of the file, absolutely strictly without spaces. This script will start automatically immediately after receiving the letter, cron and nginx are not needed, only CPanel. Actually everything.
Don't forget to give both files permission to execute locally. The solution is tested and works, just a lot of pitfalls along the way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question