ファイルタイプを使用して電子メールをスプールするようにswiftmailerを設定しました。ここ symfony - kernel.terminateでコンソールコマンドを実行
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool:
type: file
path: "%kernel.root_dir%/../var/spool"
私は任意の電子メールも完璧にスプールを送る私のではSwiftMailerの設定
です。私はその後の電子メールを送信するために次のコマンドを実行します。bin/console swiftmailer:spool:send --env=dev
symfonyのdocumentation
the console command should be triggered by a cron job or scheduled task and run at a regular interval.
によれば、私の問題は、クーロンは、私は余裕がない1分間隔の最小値を使用して構成することができるので、私はcrontabファイルを使用することはできません。私は、応答がブラウザに返された後、即座に実行するバックグラウンドプロセスを利用したいので、スプールの実行を最小限に抑えることができます。
イベントリスナークラスを作成してkernel.terminate
を聞き取り、shell_exec
またはexec
関数を使用してコマンドを実行しようとしましたが、ここでは参照用のコードです。ここで
app.kernel.terminate.listener:
arguments: ["@kernel"]
class: AppBundle\EventListener\KernelTerminateListener
tags:
- { name: kernel.event_listener, event: kernel.terminate }
私はここにしようとしています何私のEventListenerクラス
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Cocur\BackgroundProcess\BackgroundProcess;
class KernelTerminateListener
{
protected $kernel;
protected $console;
public function __construct($kernel)
{
$this->kernel = $kernel;
$this->console = $this->kernel->getRootDir().'/../bin/console ';
}
public function onKernelTerminate(PostResponseEvent $event)
{
$command = $this->console.'swiftmailer:spool:send --env='.$this->kernel->getEnvironment();
shell_exec($command);
}
}
が、残念ながら、これは動作しません、kernel.terminate
イベントでbin/console swiftmailer:spool:send --env=dev
を実行することである、この問題にアプローチする方法上の任意のヒントが理解されます。
ありがとうございます。
「これは機能しません」とはどういう意味ですか? – COil
電子メールをディスパッチしませんが、 '$ command'をechoして端末に貼り付けると動作します。私はそれが実行されても、スプールファイルは処理されませんが、通常スプールファイルが処理されると削除されることがわかります、私の場合は削除されていません。 –
'shell_exec($ command);'の出力は何の問題でしょうか? – COil