user746709
user746709

Reputation: 33

How to properly run a Symfony task in the background from an action?

$path=sfConfig::get('sf_app_module_dir')."/module/actions/MultiTheading.php";
foreach($arr as $id)
{
     if($id)
         passthru ("php -q $path $id $pid &");
}

when when i running action script is running sequenctly despite "&".

Please help

Upvotes: 0

Views: 1297

Answers (1)

Maerlyn
Maerlyn

Reputation: 34107

There are two common methods to achieve what you want.

Both involve creating a table in your database (kind of a to-do list). Your frontend saves work to do there.

The first one is easier, but it's only ok if you don't mind a slight latency. You start by creating a symfony task. When it wakes up (every 10/30/whatever minutes) it check that table if it has anything to do, simply exists if not. Otherwise it does what it needs to, then marks them as processed.

The second one is more work and more error-prone, but can work instantly. You create a task, that daemonizes itself when started (forks, forks again, and sets the parent pid to zero), then goes to sleep. If you have some work to do, you wake it up by sending a signal. Daemonizing and signal sending/receiving can be done with php's pcntl_* functions.

Upvotes: 1

Related Questions