Yii/PHP Run Background Process

Posted: February 26, 2015 in Php, Yii Framework
Tags:

To run the php process in background like sending email, call this function.

public function runBackgroundProcess($message,$mail_type, $id )
{
//Classname Action
$cmd = "Esm sendMail";
//--parameter=value --parameter=value
 $cmd = $cmd ." --message=". $message . " --type=". $mail_type . " --id=". $id;
//get the yiic path
$cmd = "php -d memory_limit=128M " . Yii::getPathOfAlias("application.yiic") . " " . $cmd;
//the php path
$cmd = "/usr/bin/".$cmd;
//write to log file
 exec($cmd . " >> /home/hafiz/log/myfile-`date '+%Y-%m-%d'`.log 2>&1 &");
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s