0

I was given a lot of legacy code using Symfony2, which was running on Linux, but I need to start it on Windows. Almost everything is working (XAMPP), but I have problem with one thing.
During the user registration, sending mails was taking too long to load confirmation page (depending on the options there could be a couple of emails), so for every email there's a record added in DB, which contains just a command, like "php /path/to/app/console product:send_some_mail address@host" etc.
Then there's a Command which takes all those not sent emails and sends it one by one. That command was previously called like this:

$proc = new Process('php /var/www/product/app/console product:send_all_mails ' . $mailAddress  .' --env='. $env . ' ');

That's quite obvious the path was not exacly right on Windows, so I tried to make it more universal. I'll paste the whole test code:

$proc = new Process('php ' . realpath($this->get('kernel')->getRootDir() . '/console') . ' product:send_all_mails ' . $mailAddress .' --env='. $env . ' ');
$proc->setEnhanceWindowsCompatibility(false); // this doesn't change anything...
$proc->start();
while($proc->isRunning()); // stupid debug
file_put_contents("MailProcessResult.txt", $proc->getCommandLine() . ' :: ' . $proc->getExitCodeText());

Strangely, everything I see in the pseudo-log file is:

php C:\gitrepos\product\app\console product:send_all_mails mymail@host.com --env=my_env :: General error

I have no idea, what's going on. I double-checked everything I could think of:

  • php.exe is in %PATH%
  • the command works, if is called from cmd, even with Windows Compatibility (cmd /V:ON /E:ON /C "(my_commandline)")
  • sendmail is configured correctly, other mails are sent without problems
  • I removed ConEmu which was taking over cmd
  • yes, on Linux it works

Earlier I tried to run the product:send_all_mails as command, but it wasn't running in background. That's quite obvious php has some problems executing php :)

What else could I try? I just need to run a batch of different Commands with different arguments from one Command (or Process) in background.

4

1 回答 1

0

将此命令更改为事件。

这样你就不需要 Process() - 我相信这是问题所在 - 太复杂了(创建进程以从系统调用命令)。

将 Event 与教义连接到 postPersist - 这将在每次创建新记录时触发事件。

在事件中检查添加到数据库的 fing 是否是用户实体,如果是,则从事件发送电子邮件

于 2015-09-27T18:46:46.600 回答