frontend/modules/mymodules/action/indexAction.class.php
// アクションクラス class mymoduleActions extends sfActions { public function executeIndex(sfWebRequest $request) { // 非同期処理テスト exec(php symfony file:test > /dev/null &); return sfView::SUCCESS; } }
lib/task/fileTestTask.class.php
// 非同期クラス class fileTestTask extends sfBaseTask { public function configure() { $this->namespace = 'file'; $this->name = 'test'; } public function execute($arguments = array(), $options = array()) { // 非同期のテスト $fh = fopen("test.txt", "w"); for ($i = 0; $i < 10; $i++) { fwrite($fh,"書き込みテスト"); sleep(5); } fclose($fh); } }
symfonyで、上記のアクションクラスと非同期処理を実行するクラスを作成しています。
<a href="/mymodule/index">非同期処理</a>
のリンクを作成し、
リンクを押すと「http://localhost/mymodule/index」に画面遷移し、
「test.txt」に値が書き込まれます。
ファイルに書き込まれている最中に、別の画面に遷移しようとリンクを押しても画面遷移しません。
ファイルの書き込みが完了後に画面遷移します。
execを使用すればバックグラウンドで処理が実行されるため、画面操作等は問題ないと思うのですが、
上記の書き方では非同期処理を実現できていないのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/30 08:33
2017/10/30 08:45
2017/10/30 09:02
2017/10/30 09:07
2017/10/30 11:12