Yii and PHP:: Executed command line and memory limit

Posted: April 27, 2011 in Php, Yii Framework
Tags:

If you’re facing the memory limit when run the php command line, set this parameter at your executed line:
php -d memory_limit=128M my_script.php
Credit to : http://cristian-radulescu.ro/article/php-cli-increase-memory-limit.html

Apply in Yii example:

/**
     * Execute command in background
     * @param string $cmd
     * $cmd = “importdata insertVoyage –voyageCode=MAMA”;
     * EG:
     * $cmd = “salarydata index –department=$department –month=$month –year=$year”;
     *  MyFunction::execCommandInBackground($cmd);
      */
    public static function execCommandInBackground($cmd){
            //$cmd = php entryScript.php CommandName ActionName –Option1=Value1 –Option2=Value2 …
            //php E:\xampp\htdocs\syscont\protected\yiic importdata insertVoyage –voyageCode=MAM0
            $cmd = “php -d memory_limit=128M ” . Yii::getPathOfAlias(“application.yiic”) . ” ” . $cmd; //here to set the command line
            if (substr(php_uname(), 0, 7) == “Windows”){
                $WshShell = new COM(“WScript.Shell”);
                $oExec = $WshShell->Run(“cmd /C ” . $cmd, 0, false);
            } else {
                ///usr/local/bin/php /home/mikrovil/public_html/haul-edge.com/protected/yiic.php invoicetransact
                $cmd = “/usr/local/bin/”.$cmd;
                exec($cmd . ” > /dev/null &”);
            }
        }

Comments
  1. […] PHP memory limit problems in command line (ie: Yiic) by flakesns. […]

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