我需要稍后再运行mail.php文件,而不是让用户在提交register.php时等待发送验证电子邮件。
因此,我选择在一分钟后在命令行上使用命令中的来运行mail.php(在register.php 中调用了):
但是,当我处于at命令的交互模式时,我只能将参数发送到该php文件。
at now + 1 minute
at> php mail.php {email} # {email} is the argument I want to pass
由于我希望这是自动的,因此我需要在运行时使用shell脚本:
at -f mail.sh
但是我找不到传递 {email} 参数的正确方法,
我尝试了来在Shell中设置一个可变的环境,但也没有用:
在 register.php 文件中,我写道:
shell_exec('export email=foo@bar.com');
shell_exec('at -f mail.sh now + 1 minute');
在 mail.sh 中,我写道:
#! /bin/bash
php mail.php $email
最佳答案
您可以从stdin中读取命令,而不是从文件中读取命令。 (bash的)here-doc语法在这里很好用:
shell_exec('at now + 1 minute <<EOF
php mail.php test@test.com
EOF
');