2013-10-17 5 views
0

저는 execign을 통해 다른 스크립트를 호출 할 때 Codeigniter 컨트롤러를 사용합니다. 모든 것은 PHP가 mod_php로로드 된 우분투에서 작동합니다. 내 프로덕션 서버에 응용 프로그램을 업로드하면 응용 프로그램에서 스크립트를 시작하지만 의도 한 컨트롤러 대신 원래 컨트롤러가 호출됩니다. 어떻게 든 아파치/CGI 여전히 내 옛 환경 변수를 가지고 추측하고있어?Codeigniter on APACHE PHP FastCGI

public function onshore_xml_queue_report() {   

    if(!$this->tank_auth->is_logged_in()) { 
     log_message('error', "Not logged in onshore_xml_queue_report"); 
     show_error("Not logged in"); 
    } 
    /* 
    else if(ENVIRONMENT == "production" && HOMEACCOUNT != "report") { 
     log_message('error', "Invalid account access onshore_xml_queue_report: " . HOMEACCOUNT); 
     show_error("Invalid Account Access");  
    } 
    */ 
    else { 

     // get report parameters       
     $this->form_validation->set_rules('year', 'Year', 'numeric|required|xss_clean'); 
     $this->form_validation->set_rules('company', 'Company', 'required|xss_clean'); 
     $this->form_validation->set_rules('analysis', 'Analysis', 'required|xss_clean'); 
     $this->form_validation->set_rules('constants', 'Constants', 'required|xss_clean'); 
     $this->form_validation->set_rules('basin', 'Basin ID', 'required|xss_clean'); 
     $this->form_validation->set_rules('email', 'Email', 'required|xss_clean'); 
     $this->form_validation->set_rules('user', 'User ID', 'required|xss_clean'); 

     // check if we have all parameters   
     if($this->form_validation->run() != FALSE) { 

      $this->output->set_content_type('application/json'); 

      // post input parameters 
      $year = intval($this->input->post('year', TRUE)); 
      $company = $this->input->post('company', TRUE); 
      $analysis = intval($this->input->post('analysis', TRUE)); 
      $constants = $this->input->post('constants', TRUE); 
      $basin = intval($this->input->post('basin', TRUE)); 
      $email = intval($this->input->post('email', TRUE)); 
      $user = intval($this->input->post('user', TRUE)); 

      // lock queue 
      $this->Queue_Model->lock("queueGhgOnshoreXML"); 

      // check if any reports are currently being processed 
      $queue = $this->Queue_Model->getQueue(); 
      $bQueueActive = FALSE; 
      foreach($queue as $entry) { 
       if($entry["processingStatus"] == 1) { 
        $bQueueActive = TRUE; 
        break; 
       } 
      } 

      log_message('debug', "Report controller queue status $bQueueActive"); 

      // enqueue report 
      $reportId = $this->Queue_Model->enqueue(array(
        "year" => $year, 
        "companyName" => $company, 
        "facilityId" => $basin, 
        "analysis" => $analysis, 
        "constants" => $constants, 
        "userId" => $user, 
        "email" => $email 
      )); 

      // if we are not currently processing, start report script via background command line 
      if(!$bQueueActive) { 

       if(count($queue) == 0) 
        $queue = $this->Queue_Model->getQueue(); 

       // FIFO queue, get earliest report id 
       $queueLength = count($queue); 
       $earliestReportId = $queue[$queueLength-1]["id"]; 

       log_message('debug', "Report controller kicking off processing script $earliestReportId"); 

       // update report record to show that we are processing 
       $this->Queue_Model->updateEntry($earliestReportId, array("processingStatus" => 1)); 

       // append any output to debug file, should never be output unless serious PHP error 
       $logFile = $this->config->item('log_path') . "onshore_xml_create_report_error.txt"; 

       log_message('debug', "Report controller logFile $logFile"); 

       $command = "nohup php index.php report onshore_xml_create_report > $logFile 2>&1 &"; 

       // 2>>&1 - causes error 
       // $command = "ls -l >> $logFile 2>&1 &";  // this works on Hostgator... 

       // http://php.net/manual/en/function.shell-exec.php 
       $output = exec($command); 

       log_message('debug', "Report controller command $command output $output"); 
      } 

      // unlock reports table 
      $this->Queue_Model->unlock(); 

      log_message('debug', "Report controller unlocked queue new report id $reportId"); 

      // return report id 
      $this->output->set_output(json_encode(array(
       "success" => true, 
       "reportId" => $reportId 
      ))); 
     } 
     else { 
      show_error("onshore_xml_queue_report: Missing Parameters"); 
     }   
    } 
} 

public function onshore_xml_create_report() { 

    log_message('debug', 'Starting onshore_xml_create_report'); 

다시 onshore_xml_create_report 기능이 내 로컬 컴퓨터와라고 onshore_xml_queue_report 프로덕션 서버에 호출됩니다

여기에 코드입니다.

답변

1

PHP에는 Codeigniter가 시스템 URI 클래스에서 명령 줄 또는 웹 요청인지 여부를 확인하는 데 사용하는 php_sapi_name 함수가 있습니다. php 인터프리터를 호출하는 새로운 프로세스를 만드는 shell_exec, exec, popen 또는 관련 함수를 호출하는 PHP에서 FastCGI가 활성화 된 Apache에서는 CLI 용으로 컴파일 된 PHP의 특정 버전을 사용하지 않는 한 여전히 부모 프로세스의 환경 변수를 사용합니다 .

/usr/bin/php는 FastCGI 컴파일 일 수 있으므로/usr/bin/php-cli를 사용해야합니다.

이것은 관련된 Stackoverflow 게시물입니다. PHP CGI replace...