i wrote a script using swift mailer to send e-mails via smtp. I noticed that it takes a fairly long time for the script to load due to the smtp sending.
I thought it would be a good idea to put the sending of that email into a seperate file. The only problem i have now is that i need to open the file.
I don't want to use fopen or anything like that because i would like that file to run "in the background" so to speak.
Is that possible without a cronjob? Is there a way to just fire that file without the user noticing it?
Thanks in advance.
您可以通过调用命令行php使用exec来执行此操作
exec('php script.php >/dev/null 2>&1 &');
another option is to have a cron script and queue table (if you have a low traffic)
Bad thing about running php background jobs is a denial of service risk. Cron can run every 2 minutes, kill another running instances and process mail queue. Running background jobs through spawning new processes is risky. And you have to remember - never pass user-defined variable to a background process.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.