在另一个脚本完成之前调用另一个 PHP 脚本并将控制权返回给用户 [英] Call another PHP script and return control to user before the other script completes

查看:36
本文介绍了在另一个脚本完成之前调用另一个 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 作业: 为此,我必须让 Cron 作业运行一次,例如每 2 分钟一次.不可行!
PHP 脚本激活 cron 作业,完成后自行停用:好吧,但我该怎么做?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

来自 Notes 部分

"如果一个程序以此启动功能,以便它继续在后台运行,输出程序必须重定向到文件或其他输出流.失败这样做会导致 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 脚本并将控制权返回给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆