我需要稍后运行一个 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
因为我希望这是自动的,所以我需要在运行 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
最佳答案
你可以使用这个:
shell_exec('echo php mail.php test@test.com | at now + 1 minute');
关于php - 如何在命令中将参数传递给 linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19980131/