在另一个脚本完成之前调用另一个PHP脚本并将控制权返回给用户
实际上我想将此应用于发送电子邮件的脚本。发送电子邮件部分需要几秒钟,时间太长。我想要的是第一个脚本做它的东西,并触发另一个脚本(发送电子邮件),但我想让第一个脚本控制返回给用户,而不必等待第二个脚本发送电子邮件。
I'm actually trying to apply this to a script that sends email. The sending email part takes a few seconds which is too long. What I want is for the first script to do its stuff and trigger another script (which sends the Email), but I want the first script to return control to the user without waiting for the second script to send the email.
我已经考虑过的选项:
Cron Job:为此,我必须有一个cron作业运行类似于每2分钟。不可行!
激活cron作业的PHP脚本完成后会自动停用:好的,但我该如何做? PHP可以这样做吗?
Options that I have considered:
Cron Job: For this I'll have to have a cron job run something like every 2 mins. Not feasible!
PHP script activating a cron job which deactivates itself when done: Well ok, but how do I do this? Can PHP do this?
也可以调用shell并手动调用PHP文件。无需cron,无需等待。
You can also call the shell and manually call the PHP file. No cron required and no waiting.
http:// www.php.net/manual/en/function.exec.php
从笔记
如果一个程序用这个
函数启动,为了继续
背景,程序的输出
必须重定向到
文件或另一个输出流。失败
将导致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."