-2

I want to run a php file in background which has some mysql commands, I am unable to do so. Is it that php file based on cakephp framework doesnot run in background? To run a php file n background do i need to write it basic php format I am a beginner. I have tried commands like:

php filename.php
php filename.php &
php -a
exec( '/usr/bin/php -f /my/path/to/filename.php > /dev/null &' );

followed this tutorial "http://www.xphp.info/background-processing-with-php/"

please tell me.

the code is:

<?php


include_once "a_file.php";


class Calci{


    var $ft = 350;
    var $fl = 130;
    var $lt = 60;    
    var $fbCount = 0;
    var $liCount = 0;
    var $twCount = 0;
    var $nodeId = 0;

    function index() {   
        App::import('model', 'User');
        $user_model = new User();

        $entry = $user_model->find("all", array("conditions" => array("not" => array("User.id" => null))));
        foreach($entry as $e) {
            $user_id = $e["User"]["id"];
            $tr=$this->getTrUser($user_id);
            $this->$e["User"]["id"]=$user_id;
            $this->$e["User"]["true_reach"]=$tr;
            $this->$e["User"]->save();
        }    
    }
    function getTrUser($id) {
// some calculation

}

}    

?>
floriank
  • 25,546
  • 9
  • 42
  • 66

3 Answers3

0

You need to use php-cli, to execute php script using exec

exec('php-cli /var/www/gohachi-git/app/services/hachicalci.php > /dev/null &');
kamal pal
  • 4,187
  • 5
  • 25
  • 40
0

If your using SSH / Terminal use:

nohup php /my/path/to/filename.php &
Danny Broadbent
  • 1,199
  • 1
  • 9
  • 21
0

I think the best approach is to use the Mysql Event Scheduler and Stored Procedures for run this queries.

An4Th3mA
  • 39
  • 2