我实际上是在尝试将其应用于发送电子邮件的脚本。发送电子邮件部分需要几秒钟,太长了。我想要的是让第一个脚本完成它的工作并触发另一个脚本(发送电子邮件),但我希望第一个脚本将控制权返回给用户,而无需等待第二个脚本发送电子邮件。
我考虑过的选项:
Cron Job: 为此,我必须让 cron 作业每 2 分钟运行一次。不可行!
激活 cron 作业的 PHP 脚本在完成后会自行停用:好吧,但是我该怎么做呢? PHP 可以做到这一点吗?
最佳答案
也可以调用shell,手动调用PHP文件。不需要 cron,也不需要等待。
http://www.php.net/manual/en/function.exec.php
来自注释
部分
"If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends."
关于php - 调用另一个 PHP 脚本并在另一个脚本完成之前将控制权返回给用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5103528/