[Erunactions] How To Execute Shell Php

Hi all,

First of all thank you for this forum. It’s very usefull!

I had to execute a shell php (like as $>php ./test.php) and I find the RunActions extention, but I don’t understand how to use it.

In my controller, I create a new method and put in this code


public function actionTest()

        {

            Yii::import('ext.runactions.components.ERunActions');

            

            if (ERunActions::runBackground())

            {

               Yii::log('Starting background task...');


               ERunActions::touchUrlExt("/home/public_html/proyect/testaction.php",$postData=null,$contentType=null,$httpClientConfig=array());

               

               //Inform the user if 'hasFlash' is implemented in all views

               Yii::app()->user->setFlash('runbackground','Process finished');


               Yii::log('Background task executed');

               Yii::app()->end(); 

            }else{

                echo "Finish!!!";                

            }

        }

To test it, the code testaction.php, open and write into a log file.

I checked on application.log, but I didn’t find any errors, so I don’t understand where is the problem.

have any suggestion to solve it?

Thank you!

Maybe run it as Yii console application?

http://www.yiiframework.com/doc/guide/1.1/en/topics.console

Thank you for your reply.

I’m checking your suggestion.

But I don’t understand why I cannot use the ERunActions. In particulary, I don’t understand why it doesn’t this if.


if (ERunActions::runBackground())

{

....

}

My goal is

  1. Click on button

  2. execute a .php (without parameter). The .php is on another server, but I have the permission to execute it

  3. Return to the user a message, when the .php ends. (note: Only one admin user will use this procedure)

Best regards

Am I following you correctly that you like to execute script like a cron and then user should be notified?

In this case:




Yii::app()->user->setFlash('runbackground','Process finished');



has no use. It sets the flash into session where the script is being executed from. It is not a "superglobal" variable or how is it called properly. Maybe better idea, is to change value in users sql, and if condition is reached the setflash is called(when user browses something).

But the goal is easily reachable with Yii command line. It runs perfectly over ssh (./yiic). I can’t say why the ERunActions is not working, you can debug it with var_dumps or die’s to see how far the code is beign executed.