src/AbstractDaemon.php
protected function changeIdentity()
	{
		// Get the group and user ids to set for the daemon.
		$uid = (int) $this->get('application_uid', 0);
		$gid = (int) $this->get('application_gid', 0);

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

		// Change the user id for the process id file if necessary.
		if ($uid && (fileowner($file) != $uid) && (!@ chown($file, $uid)))
		{
			$this->getLogger()->error('Unable to change user ownership of the process id file.');

			return false;
		}

		// Change the group id for the process id file if necessary.
		if ($gid && (filegroup($file) != $gid) && (!@ chgrp($file, $gid)))
		{
			$this->getLogger()->error('Unable to change group ownership of the process id file.');

			return false;
		}

		// Set the correct home directory for the process.
		if ($uid && ($info = posix_getpwuid($uid)) && is_dir($info['dir']))
		{
			system('export HOME="' . $info['dir'] . '"');
		}

		// Change the user id for the process necessary.
		if ($uid && (posix_getuid() != $uid) && (!@ posix_setuid($uid)))
		{
			$this->getLogger()->error('Unable to change user ownership of the proccess.');

			return false;
		}

		// Change the group id for the process necessary.
		if ($gid && (posix_getgid() != $gid) && (!@ posix_setgid($gid)))
		{
			$this->getLogger()->error('Unable to change group ownership of the proccess.');

			return false;
		}

		// Get the user and group information based on uid and gid.
		$user  = posix_getpwuid($uid);
		$group = posix_getgrgid($gid);

		$this->getLogger()->info('Changed daemon identity to ' . $user['name'] . ':' . $group['name']);

		return true;
	}
protected function changeIdentity()
	{
		// Get the group and user ids to set for the daemon.
		$uid = (int) $this->get('application_uid', 0);
		$gid = (int) $this->get('application_gid', 0);

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

		// Change the user id for the process id file if necessary.
		if ($uid && (fileowner($file) != $uid) && (!@ chown($file, $uid)))
		{
			$this->getLogger()->error('Unable to change user ownership of the process id file.');

			return false;
		}

		// Change the group id for the process id file if necessary.
		if ($gid && (filegroup($file) != $gid) && (!@ chgrp($file, $gid)))
		{
			$this->getLogger()->error('Unable to change group ownership of the process id file.');

			return false;
		}

		// Set the correct home directory for the process.
		if ($uid && ($info = posix_getpwuid($uid)) && is_dir($info['dir']))
		{
			system('export HOME="' . $info['dir'] . '"');
		}

		// Change the user id for the process necessary.
		if ($uid && (posix_getuid() != $uid) && (!@ posix_setuid($uid)))
		{
			$this->getLogger()->error('Unable to change user ownership of the proccess.');

			return false;
		}

		// Change the group id for the process necessary.
		if ($gid && (posix_getgid() != $gid) && (!@ posix_setgid($gid)))
		{
			$this->getLogger()->error('Unable to change group ownership of the proccess.');

			return false;
		}

		// Get the user and group information based on uid and gid.
		$user  = posix_getpwuid($uid);
		$group = posix_getgrgid($gid);

		$this->getLogger()->info('Changed daemon identity to ' . $user['name'] . ':' . $group['name']);

		return true;
	}
protected function changeIdentity ( ) { // Get the group and user ids to set for the daemon. $ uid = ( int ) $ this -> get ( 'application_uid' , 0 ) ; $ gid = ( int ) $ this -> get ( 'application_gid' , 0 ) ; // Get the application process id file path. $ file = $ this -> get ( 'application_pid_file' ) ; // Change the user id for the process id file if necessary. if ( $ uid && ( fileowner ( $ file ) != $ uid ) && ( ! @ chown ( $ file , $ uid ) ) ) { $ this -> getLogger ( ) -> error ( 'Unable to change user ownership of the process id file.' ) ; return false ; } // Change the group id for the process id file if necessary. if ( $ gid && ( filegroup ( $ file ) != $ gid ) && ( ! @ chgrp ( $ file , $ gid ) ) ) { $ this -> getLogger ( ) -> error ( 'Unable to change group ownership of the process id file.' ) ; return false ; } // Set the correct home directory for the process. if ( $ uid && ( $ info = posix_getpwuid ( $ uid ) ) && is_dir ( $ info [ 'dir' ] ) ) { system ( 'export HOME="' . $ info [ 'dir' ] . '"' ) ; } // Change the user id for the process necessary. if ( $ uid && ( posix_getuid ( ) != $ uid ) && ( ! @ posix_setuid ( $ uid ) ) ) { $ this -> getLogger ( ) -> error ( 'Unable to change user ownership of the proccess.' ) ; return false ; } // Change the group id for the process necessary. if ( $ gid && ( posix_getgid ( ) != $ gid ) && ( ! @ posix_setgid ( $ gid ) ) ) { $ this -> getLogger ( ) -> error ( 'Unable to change group ownership of the proccess.' ) ; return false ; } // Get the user and group information based on uid and gid. $ user = posix_getpwuid ( $ uid ) ; $ group = posix_getgrgid ( $ gid ) ; $ this -> getLogger ( ) -> info ( 'Changed daemon identity to ' . $ user [ 'name' ] . ':' . $ group [ 'name' ] ) ; return true ; }
Method to change the identity of the daemon process and resources.

@return  boolean  True if identity successfully changed

@since   1.0
@see     posix_setuid()
Method to change the identity of the daemon process and resources .