/**
* Method to write the process id file out to disk.
*
* @return boolean
*
* @since 1.7.0
*/
protected function writeProcessIdFile()
{
// Verify the process id is valid.
if ($this->processId < 1) {
Log::add('The process id is invalid.', Log::EMERGENCY);
return false;
}
// Get the application process id file path.
$file = $this->config->get('application_pid_file');
if (empty($file)) {
Log::add('The process id file path is empty.', Log::ERROR);
return false;
}
// Make sure that the folder where we are writing the process id file exists.
$folder = \dirname($file);
if (!is_dir($folder) && !Folder::create($folder)) {
Log::add('Unable to create directory: ' . $folder, Log::ERROR);
return false;
}
// Write the process id file out to disk.
if (!file_put_contents($file, $this->processId)) {
Log::add('Unable to write process id file: ' . $file, Log::ERROR);
return false;
}
// Make sure the permissions for the process id file are accurate.
if (!chmod($file, 0644)) {
Log::add('Unable to adjust permissions for the process id file: ' . $file, Log::ERROR);
return false;
}
return true;
}