【发布时间】:2014-09-11 13:21:42
【问题描述】:
当我为后台进程调用 background.php 时,执行需要时间。执行后它将执行其余代码。我想在后台进程中执行它。它不应该等待执行。
在我的 index.php 文件下方
session_start();
$session_id = session_id();
$_SESSION['album_upload'] = "body message";
$command = file_get_contents('background.php');
$process = new PhpProcess($command, null, array('session_id' => $session_id));
$process->run(); // Taking time for execution which should not.
//I have also check to using `$process->start();` but it doesn't run the backround.php(I guess because I doesn't get email.).
background.php代码如下
session_id($_SERVER['session_id']);
session_start();
mail("webmaster@example.com","example",$_SESSION['album_upload'],"From: $from\n");
// I also doing some copy() from another server to my server So it's take a long time.
我真的需要在后台进程中执行它。请给我解决方案。
【问题讨论】:
-
您确定这不是并行过程吗?应该是...
-
@DonCallisto 是的。我明白了... $process->start() 将在后台运行代码而不会阻塞。但是,Symfony 会在其主线程完成时自动停止子进程,因此您的电子邮件可能无法发送.... 如何解决?
标签: php symfony background-process