Getting the process ID of a Yii Console Application

Hi, I am new to Yii and it’s been great so far!

I have a console application that serves as a listener for incoming xmpp messages. So I run it by

nohup php console.php Listener

If I need to restart it, I get its process ID by

ps aux | grep console.php

then kill its process ID.

The console app is supposed to run for always. However, sometimes it gets killed (by mysql error "Mysql server has gone away."). So what I would like to do is to automatically restart the console application. My idea to do this is by following the suggestion from stackoverflow ( by writing a shell script like below:


while [true]; do

    if ! pidof -x console.php;


        nohup php console.php Listener &



To test, I tried to run in the linux terminal

pidof -x console.php

, but it just returns blank.

I also tried

pidof -x console.php Listener

, and

pidof -x "console.php Listener"

and got the same blank result.

Do you have any idea on how to get the pid of the Yii console application?

Or can you suggest any other approach to automatically restart the Yii console application? Thanks!

Try this:


class MyApp extends CConsoleApplication


  protected $pid = null;

  public function __construct( $action, $params){{

    parent::__construct( $action, $params );

    $this->pid = posix_getpid();



  public function __destruct(){{






And kill script:


PID=($( /bin/cat /tmp/ ))

kill $PID