Call another PHP script and return control to user before the other script completes

前端 未结 4 2050
情话喂你
情话喂你 2020-11-30 14:50

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

相关标签:
4条回答
  • 2020-11-30 14:59

    Other solution :

    • Your script put a token somewhere (DB/filesystem) when a mail needs to be sent (token may contain data for mail generation)
    • A daemon (can be written in php) runs in the background looking for tokens and "eats" them to send mail

    I use this kind of solution quite a lot ...

    0 讨论(0)
  • I am using jQuery and AJAX to do stuff like this for PHP scripts which take long time.

    0 讨论(0)
  • 2020-11-30 14:59

    What you want to use is something called beanstalkd

    Details: How can I get a list of all jobs in a beanstalk tube?

    It will allow you to queue up jobs (do 1, then 2, then 3. then 4) you can even distribute these tasks across servers (yes for php jobs!).

    0 讨论(0)
  • 2020-11-30 15:17

    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

    From the Notes Section

    "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."

    0 讨论(0)
提交回复
热议问题