문제

나는 코드 점화기 라이브러리를 사용하여 데몬 프로세스를 작성하려고 노력하고 있는데,문제는 데몬 프로세스를 포크 할 때 더 이상 시 인스턴스에 액세스 할 수 없으며__구성에서 초기화 된 모든 라이브러리도 액세스 할 수 없으며 자식 프로세스에서 새 시 인스턴스를 만들면 여전히 라이브러리에 액세스 할 수 없으며 다음과 같은 오류가 발생합니다.:

오류-2012-02-27 00:13:07-->심각도:경고->포함(응용 프로그램/오류/오류_일반.):스트림을 열지 못했습니다.:이러한 파일 또는 디렉토리가 없습니다.146 오류-2012-02-27 00:13:07-->심각도:경고-->포함():실패 열기'응용 프로그램/오류/오류_일반.예를 들면 다음과 같습니다.이 경우,당신은 그것을 할 수 없습니다.146

여기 내 코드가 있습니다:

class Conversion_workers
{
    function __construct() {
        $this->ci =& get_instance();
        $this->ci->load->library('Gearman');
    }

    private function is_locked($lock_file) {
        if(file_exists($lock_file)) {
            $lock = fopen($lock_file,"c+"); // open it for WRITING ("w")
            if (! flock($lock, LOCK_EX | LOCK_NB)) {
                flock($lock, LOCK_UN);
                return TRUE;
            }
        }
        return FALSE;
    }


    private function lock_file($lock_file, &$lock) {
        $lock = fopen($lock_file,"c+"); // open it for WRITING ("w")
        if (! flock($lock, LOCK_EX | LOCK_NB)) {
            //error_log('Unable to lock file.');
            return FALSE;
        }
        fseek($lock, 0);
        ftruncate($lock, 0);
        fwrite($lock, posix_getpid());
        fflush($lock);  
        return TRUE;
    }


    private function daemonize($lock_file, &$lock, &$parent)
    {

        // TODO: In the install check if pcntl_fork supported
        if($this->is_locked($lock_file)) {

            $parent = TRUE;
            return FALSE;
        }

        $pid = pcntl_fork();
        if($pid < 0) {
            log_message('error', 'Unable to fork process');
            return FALSE;
        }

        // If we got a good PID, then we can exit the parent process. 
        if($pid > 0) {
            log_message('info', 'Exiting parent as process forked successfully');
            $parent = TRUE;
            return FALSE;
        }

        ob_start();

        // Change the file mode mask 
        umask(0);

        // Create a new SID for the child process
        if (posix_setsid() < 0) {
            //error_log('Unable to create a new SID for child process');
            return FALSE;
        }

        // Change the current working directory 
        if(chdir("/tmp") < 0) {
            //error_log('Unable to change directory of the daemonize process');
            return FALSE;
        }

        // Lock in child process to get correct pid in lock file
        if(!$this->lock_file($lock_file, $lock)) {
            exit;
        }

        fclose(STDIN);  // Close all of the standard
        fclose(STDOUT); // file descriptors as we
        fclose(STDERR); // are running as a daemon.

        register_shutdown_function(create_function('$pars', 
            'ob_end_clean();posix_kill(posix_getpid(), SIGKILL);'), array());

        // Might be good idea to have register_shutdown_function() here if we want to 
        // check status when the daemon terminates.

        return TRUE;
    } 

   private function start_workers() {

        $lock_file  = $this->ci->config->item('lock_file');
        $parent     = FALSE; 

        if(! $this->daemonize($lock_file, $lock, $parent)) {
            if($parent)
                return;

        } else {

            // Start a worker
            $this->ci->gearman->gearman_worker();
            $this->ci->gearman->add_worker_function('some_function', 'some_function_fn'); 

            error_log('Starting worker ['.posix_getpid().']');

            while($this->ci->gearman->work());
        }

        error_log('Exiting worker');
        exit;
    }

    function add_to_queue($function_name, $params) {
        $this->start_workers();

        $this->ci->gearman->gearman_client();
        return $this->ci->gearman->do_job_background($function_name, serialize($params)); 
    }
} // END class Controller

이 응용 프로그램을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.이 기능을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.이 기능을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.이 기능을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.이 기능을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.이 기능을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.이 기능을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.이 기능을 사용하면 로그 도우미 기능에 액세스 할 수 없습니다.

누군가가 제발 도움이 될 수 있다면 나는 감사하게 될 것입니다.

도움이 되었습니까?

해결책

데모니즈 메서드가 작업 디렉터리를 다음과 같이 변경했을 수 있습니다 /tmp?이 경우 시스템은 다음을 포함합니다 .(/티엠피)와 /usr/share/pear, 둘 중 어느 것도 그들을 붙잡지 않습니까?

아마도 http://www.php.net/manual/en/ini.core.php#ini.include-path 도움이 될 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top