protected function writeProcessIdFile()
    {
        // Verify the process id is valid.
        if ($this->processId < 1) {
            $this->getLogger()->emergency('The process id is invalid.');

            return false;
        }

        // Get the application process id file path.
        $file = $this->config->get('application_pid_file');

        if (empty($file)) {
            $this->getLogger()->error('The process id file path is empty.');

            return false;
        }

        // Make sure that the folder where we are writing the process id file exists.
        $folder = dirname($file);

        if (!is_dir($folder) && !@ mkdir($folder, $this->get('folder_permission', 0755))) {
            $this->getLogger()->error('Unable to create directory: ' . $folder);

            return false;
        }

        // Write the process id file out to disk.
        if (!file_put_contents($file, $this->processId)) {
            $this->getLogger()->error('Unable to write proccess id file: ' . $file);

            return false;
        }

        // Make sure the permissions for the proccess id file are accurate.
        if (!chmod($file, $this->get('file_permission', 0644))) {
            $this->getLogger()->error('Unable to adjust permissions for the proccess id file: ' . $file);

            return false;
        }

        return true;
    }