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