/** * Constructor. * * @param Master $master The master object * @param integer $pid The child process id or null if this is the child * * @throws \Exception * @throws \RuntimeException */ public function __construct(Master $master, $pid = null) { $this->master = $master; $directions = array('up', 'down'); if (null === $pid) { // child $pid = posix_getpid(); $pPid = posix_getppid(); $modes = array('write', 'read'); } else { // parent $pPid = null; $modes = array('read', 'write'); } $this->pid = $pid; $this->ppid = $pPid; foreach (array_combine($directions, $modes) as $direction => $mode) { $fifo = $this->getPath($direction); if (!file_exists($fifo) && !posix_mkfifo($fifo, 0600) && 17 !== ($error = posix_get_last_error())) { throw new \Exception(sprintf('Error while creating FIFO: %s (%d)', posix_strerror($error), $error)); } $this->{$mode} = fopen($fifo, $mode[0]); if (false === ($this->{$mode} = fopen($fifo, $mode[0]))) { throw new \RuntimeException(sprintf('Unable to open %s FIFO.', $mode)); } } }
/** * Daemonize the current process so it can run in the background. * * If $pidfile is supplied, the process ID is written there. * Provide absolute path names for the parameters to avoid file not found errors or logs inside the source code folder. * * If an error occurred, a RuntimeException is thrown. * * @param string $pidfile File to write the process ID of the daemon to * @param string $stderr File to redirect STDERR to * @param string $stdout File to redirect STDOUT to * @param string $stdin File to read STDIN from * @throws \RuntimeException * @return true */ public static function daemonize($pidfile = null, $stderr = '/dev/null', $stdout = '/dev/null', $stdin = '/dev/null') { // Allow only cli scripts to daemonize, otherwise you may confuse your webserver if (\php_sapi_name() !== 'cli') { throw new \RuntimeException('Can only daemonize a CLI process!'); } self::checkPID($pidfile); self::reopenFDs($stdin, $stdout, $stderr); if (($pid1 = @\pcntl_fork()) < 0) { throw new \RuntimeException('Failed to fork, reason: "' . \pcntl_strerror(\pcntl_get_last_error()) . '"'); } elseif ($pid1 > 0) { exit; } if (@posix_setsid() === -1) { throw new \RuntimeException('Failed to become session leader, reason: "' . \posix_strerror(\posix_get_last_error()) . '"'); } if (($pid2 = @\pcntl_fork()) < 0) { throw new \RuntimeException('Failed to fork, reason: "' . \pcntl_strerror(\pcntl_get_last_error()) . '"'); } elseif ($pid2 > 0) { exit; } chdir('/'); umask(022); self::writePID($pidfile); return true; }
public function open($fifoFile) { $this->fifoFile = $fifoFile; $dir = pathinfo($this->fifoFile, PATHINFO_DIRNAME); umask(0); $this->selfCreated = false; if (!is_dir($dir)) { if (!mkdir($dir, 0777, true)) { throw new \Exception("Could not create directory {$dir}"); } } // If pipe was not create on another side if (!file_exists($this->fifoFile)) { if (!posix_mkfifo($this->fifoFile, 0777)) { throw new \Exception("Could not create {$this->fifoFile}: " . posix_strerror(posix_get_last_error())); } else { $this->selfCreated = true; } } log::debug("Creating stream for {$this->fifoFile}"); $stream = fopen($this->fifoFile, "c+"); log::debug("Stream {$stream} = {$this->fifoFile}"); $this->valid = (bool) $stream; parent::open($stream); $this->setBlocking(false); }
/** * Returns text of last system error * * @return string */ public function error() { if (!function_exists('posix_get_last_error')) { return 'n/a'; } return posix_strerror(posix_get_last_error()); }
/** * 尝试开始任务 * * @return boolean */ protected function tryStart() { // 检查是否达到预定时间 try { if (!$this->testTimer()) { return false; } } catch (\Exception $ex) { $this->log('error', 'Job testTimer() error', ['error' => $ex->getMessage()]); return false; } // 上下文中是否保存了前一个任务pid if (!($recent_proc_id = $this->getContext(self::KEY_PROC_ID))) { return true; } // 检查进程ID是否真正存在 if (!posix_kill($recent_proc_id, 0)) { $errno = posix_get_last_error(); if ($errno === 3) { return true; } $this->log('warning', 'Job kill error', ['error' => posix_strerror($errno)]); return false; } // 如果上一个任务还没有超时就放弃当前任务 $recent_proc_time = $this->getContext(self::KEY_PROC_TIME); if (time() - $recent_proc_time < $this->timeout) { $this->log('notice', 'Job cancel, previous job still run', ['previous_proc_id' => $recent_proc_id]); return false; } // 中止超时任务 posix_kill($recent_proc_id, SIGKILL); $this->log('warning', 'Job killed by timeout', ['previous_proc_id' => $recent_proc_id]); return true; }
public static function setUid($uid, $gid) { if (!posix_setgid($gid)) { // 必须先设置GID, 再设置UID throw new Exception("Unable to set GID: " . posix_strerror(posix_get_last_error())); } if (!posix_setuid($uid)) { throw new Exception("Unable to set UID: " . posix_strerror(posix_get_last_error())); } }
function kill_concentrator() { $result = posix_kill($this->concentrator_pid, SIGTERM); if ($result === FALSE) { $errno = posix_get_last_error(); throw new Exception("Error killing off mysql concentrator: {$errno}: " . posix_strerror($errno) . "\n"); } $status = null; $result = pcntl_waitpid($this->concentrator_pid, $status); if ($result == -1) { $errno = posix_get_last_error(); throw new Exception("Error waiting for concentrator ({$this->concentrator_pid}): {$errno}: " . posix_strerror($errno) . "\n"); } }
/** * Wait for all child processes to complete */ public function wait() { // Wait for all children to return foreach ($this->child_pid_list as $child_pid) { if (pcntl_waitpid($child_pid, $status) < 0) { error_log(posix_strerror(posix_get_last_error())); } // Check to see if the child died a graceful death $status = 0; if (pcntl_wifsignaled($status)) { $return_code = pcntl_wexitstatus($status); $term_sig = pcntl_wtermsig($status); error_log("Child terminated with return code {$return_code} and signal {$term_sig}"); } } }
/** * @param int $pool_size * The number of worker processes to create * * @param array $task_data_iterator * An array of task data items to be divided up among the * workers * * @param \Closure $startup_closure * A closure to execute upon starting a child * * @param \Closure $task_closure * A method to execute on each task data * * @param \Closure $shutdown_closure * A closure to execute upon shutting down a child */ public function __construct(int $pool_size, array $task_data_iterator, \Closure $startup_closure, \Closure $task_closure, \Closure $shutdown_closure) { assert($pool_size > 1, 'The pool size must be >= 2 to use the fork pool.'); assert(extension_loaded('pcntl'), 'The pcntl extension must be loaded in order for Phan to be able to fork.'); // We'll keep track of if this is the parent process // so that we can tell who will be doing the waiting $is_parent = false; // Fork as many times as requested to get the given // pool size for ($proc_id = 0; $proc_id < $pool_size; $proc_id++) { // Fork $pid = 0; if (($pid = pcntl_fork()) < 0) { error_log(posix_strerror(posix_get_last_error())); exit(EXIT_FAILURE); } // Parent if ($pid > 0) { $is_parent = true; $this->child_pid_list[] = $pid; continue; } // Child if ($pid === 0) { $is_parent = false; break; } } // If we're the parent, return if ($is_parent) { return; } // Execute anything the children wanted to execute upon // starting up $startup_closure(); // Otherwise, take on a slice of the task list foreach ($task_data_iterator as $i => $task_data) { if ($i % $pool_size === $proc_id) { $task_closure($i, $task_data); } } // Execute each child's shutdown closure before // exiting the process $shutdown_closure(); // Children exit after completing their work exit(EXIT_SUCCESS); }
<?php $file = 'some_file'; if (posix_access($file, POSIX_R_OK | POSIX_W_OK)) { echo 'The file is readable and writable!'; } else { $error = posix_get_last_error(); echo "Error {$error}: " . posix_strerror($error); }
<?php /* Prototype : proto string posix_strerror(int errno) * Description: Retrieve the system error message associated with the given errno. * Source code: ext/posix/posix.c * Alias to functions: */ echo "*** Testing posix_strerror() : error conditions ***\n"; echo "\n-- Testing posix_strerror() function with Zero arguments --\n"; var_dump(posix_strerror()); echo "\n-- Testing posix_strerror() function with more than expected no. of arguments --\n"; $errno = posix_get_last_error(); $extra_arg = 10; var_dump(posix_strerror($errno, $extra_arg)); echo "\n-- Testing posix_strerror() function with invalid error number --\n"; $errno = -999; echo gettype(posix_strerror($errno)) . "\n"; echo "Done";
/** * @return TransportException */ public static function posixError() { return new self(sprintf('Posix error [%s]: "%s"', posix_get_last_error(), posix_strerror(posix_get_last_error()))); }
/** * Get Error Message for Error Number * * @param int $errno A POSIX error number, returned by posix_get_last_error(). If set to 0, then the string "Success" is returned. * * @return string */ public function strerror($errno) { return posix_strerror($errno); }
function killProcessAndChilds($pid) { exec("ps -ef| awk '\$3 == '{$pid}' { print \$2 }'", $output, $ret); if ($ret) { return 'you need ps, grep, and awk'; } while (list(, $t) = each($output)) { if ($t != $pid) { killProcessAndChilds($t); } } //echo "killing ".$pid."\n"; posix_kill($pid, SIGINT); posix_kill($pid, SIGSTOP); posix_kill($pid, SIGKILL); $err = posix_get_last_error(); if ($err) { doPrint("failed to signal " . $pid . ": " . posix_strerror($err)); doPrint(getPidData($pid)); } }
function stdapi_sys_process_kill($req, &$pkt) { # The existence of posix_kill is unlikely (it's a php compile-time option # that isn't enabled by default, but better to try it and avoid shelling # out when unnecessary. my_print("doing kill"); $pid_tlv = packet_get_tlv($req, TLV_TYPE_PID); $pid = $pid_tlv['value']; if (is_callable('posix_kill')) { $ret = posix_kill($pid, 9); $ret = $ret ? ERROR_SUCCESS : posix_get_last_error(); if ($ret != ERROR_SUCCESS) { my_print(posix_strerror($ret)); } } else { $ret = ERROR_FAILURE; if (is_windows()) { my_cmd("taskkill /f /pid {$pid}"); # Don't know how to check for success yet, so just assume it worked $ret = ERROR_SUCCESS; } else { if ("foo" == my_cmd("kill -9 {$pid} && echo foo")) { $ret = ERROR_SUCCESS; } } } return $ret; }
public function run() { proc_nice(Daemon::$settings['workerpriority']); Daemon::$worker = $this; $this->microsleep = Daemon::$settings['microsleep']; $this->autoReloadLast = time(); $this->reloadDelay = Daemon::$parsedSettings['mpmdelay'] + 2; $this->setStatus(4); Thread::setproctitle(Daemon::$runName . ': worker process' . (Daemon::$settings['pidfile'] !== Daemon::$settings['defaultpidfile'] ? ' (' . Daemon::$settings['pidfile'] . ')' : '')); register_shutdown_function(array($this, 'shutdown')); if (Daemon::$settings['autogc'] > 0) { gc_enable(); } else { gc_disable(); } if (isset(Daemon::$settings['group'])) { $sg = posix_getgrnam(Daemon::$settings['group']); } if (isset(Daemon::$settings['user'])) { $su = posix_getpwnam(Daemon::$settings['user']); } if (Daemon::$settings['chroot'] !== '/') { if (posix_getuid() != 0) { Daemon::log('You must have the root privileges to change root.'); exit(0); } elseif (!chroot(Daemon::$settings['chroot'])) { Daemon::log('Couldn\'t change root to \'' . Daemon::$settings['chroot'] . '\'.'); exit(0); } } if (isset(Daemon::$settings['group'])) { if ($sg === FALSE) { Daemon::log('Couldn\'t change group to \'' . Daemon::$settings['group'] . '\'. You must replace config-variable \'group\' with existing group.'); exit(0); } elseif ($sg['gid'] != posix_getgid() && !posix_setgid($sg['gid'])) { Daemon::log('Couldn\'t change group to \'' . Daemon::$settings['group'] . "'. Error (" . ($errno = posix_get_last_error()) . '): ' . posix_strerror($errno)); exit(0); } } if (isset(Daemon::$settings['user'])) { if ($su === FALSE) { Daemon::log('Couldn\'t change user to \'' . Daemon::$settings['user'] . '\', user not found. You must replace config-variable \'user\' with existing username.'); exit(0); } elseif ($su['uid'] != posix_getuid() && !posix_setuid($su['uid'])) { Daemon::log('Couldn\'t change user to \'' . Daemon::$settings['user'] . "'. Error (" . ($errno = posix_get_last_error()) . '): ' . posix_strerror($errno)); exit(0); } } if (Daemon::$settings['cwd'] !== '.') { if (!@chdir(Daemon::$settings['cwd'])) { Daemon::log('WORKER ' . $this->pid . '] Couldn\'t change directory to \'' . Daemon::$settings['cwd'] . '.'); } } $this->setStatus(6); $this->eventBase = event_base_new(); Daemon::$appResolver->preload(); foreach (Daemon::$appInstances as $app) { foreach ($app as $appInstance) { if (!$appInstance->ready) { $this->ready = TRUE; $appInstance->onReady(); } } } $this->setStatus(1); $ev = event_new(); event_set($ev, STDIN, EV_TIMEOUT, function () { }, array()); event_base_set($ev, $this->eventBase); $this->timeoutEvent = $ev; while (TRUE) { pcntl_signal_dispatch(); if (($s = $this->checkState()) !== TRUE) { $this->closeSockets(); if (sizeof($this->queue) === 0) { return $s; } } event_add($this->timeoutEvent, $this->microsleep); event_base_loop($this->eventBase, EVLOOP_ONCE); do { for ($i = 0, $s = sizeof($this->eventsToAdd); $i < $s; ++$i) { event_add($this->eventsToAdd[$i]); unset($this->eventsToAdd[$i]); } $this->readPool(); $processed = $this->runQueue(); } while ($processed || $this->readPoolState || $this->eventsToAdd); } }
/** * * Shutdown function is call if script terminates try to make a restart if needed * * Prepare the job for start * * @internal param int the signal that terminates the job */ public function shutdown() { //Put last error to log if one $lasterror = error_get_last(); if ($lasterror['type'] === E_ERROR || $lasterror['type'] === E_PARSE || $lasterror['type'] === E_CORE_ERROR || $lasterror['type'] === E_CORE_WARNING || $lasterror['type'] === E_COMPILE_ERROR || $lasterror['type'] === E_COMPILE_WARNING) { $this->log($lasterror['type'], $lasterror['message'], $lasterror['file'], $lasterror['line']); } $error = false; if (function_exists('pcntl_get_last_error')) { $error = pcntl_get_last_error(); if (!empty($error)) { $error_msg = pcntl_strerror($error); if (!empty($error_msg)) { $error = '(' . $error . ') ' . $error_msg; } } if (!empty($error)) { $this->log(sprintf(__('System: %s', 'backwpup'), $error), E_USER_ERROR); } } if (function_exists('posix_get_last_error') && !$error) { $error = posix_get_last_error(); if (!empty($error)) { $error_msg = posix_strerror($error); if (!empty($error_msg)) { $error = '(' . $error . ') ' . $error_msg; } } if (!empty($error)) { $this->log(sprintf(__('System: %s', 'backwpup'), $error), E_USER_ERROR); } } $this->do_restart(true); }
/** * Terminate a process and any of its children. */ private static function terminate_proc($proc) { $status = proc_get_status($proc); $master_pid = $status['pid']; $output = `ps -o ppid,pid,command | grep ^{$master_pid}`; foreach (explode("\n", $output) as $line) { if (preg_match('/^(\\d+)\\s+(\\d+)/', $line, $matches)) { $parent = $matches[1]; $child = $matches[2]; if ($parent == $master_pid) { if (!posix_kill($child, 9)) { throw new RuntimeException(posix_strerror(posix_get_last_error())); } } } } posix_kill($master_pid, 9); }
/** * startup time utility to write our pid to pidfile. * * We check for stale pidfile and remove it if necessary. */ public function createpidfile() { if (file_exists($this->pidfile)) { $this->log->error("Pidfile '%s' already exists", $this->pidfile); $this->droppidfile(); } $fd = fopen($this->pidfile, "w+"); if ($fd !== false) { if (fwrite($fd, getmypid()) === False) { $this->log->fatal("Pidfile fwrite('%s') failed: %s", $this->pidfile, posix_strerror(posix_get_last_error())); $this->droppidfile(); exit(2); } if (fclose($fd) === False) { $this->log->fatal("Pidfile fclose('%s') failed: %s", $this->pidfile, posix_strerror(posix_get_last_error())); $this->droppidfile(); exit(2); } } else { $this->log->fatal("Pidfile fopen('%s') failed: %s", $this->pidfile, posix_strerror(posix_get_last_error())); exit(2); } $this->log->notice("Pidfile '%s' created with '%s'", $this->pidfile, getmypid()); }
echo "<h4>$stop not stopped!</h4>"; } }else{ echo "<h4>$stop not running!</h4>"; } }elseif($clear and $isadmin){ $query = GenQuery('system','u','name','=','threads',array('value'),array(),array('0') ); if( !DbQuery($query,$link) ){echo "<h4>".DbError($link)."</h4>";}else{echo "<h5>$dellbl threads OK</h5>";} $query = GenQuery('system','u','name','=','nodlock',array('value'),array(),array('0') ); if( !DbQuery($query,$link) ){echo "<h4>".DbError($link)."</h4>";}else{echo "<h5>$reslbl nodlock OK</h5>";} if( $pid = GetPID('nedi.pl') ){ posix_kill ($pid, 9); $err = posix_get_last_error(); if( $err ){ echo "<h4>$dellbl NeDi: ".posix_strerror($err)."</h4>"; }else{ echo "<h5>NeDi $dellbl OK</h5>"; } $procs = shell_exec($pscmd); # Refresh PIDs after kill }else{ echo "<h4>NeDi not running</h4>"; } } $query = GenQuery('system','s'); $res = DbQuery($query,$link); while( $s = DbFetchRow($res) ){ $sys[$s[0]] = $s[1]; } DbFreeResult($res);
public function pushLoop($ident) { $this->reopenLog($ident); while (TRUE) { $this->reloadConfig($ident); try { unset($errorcode); if (!msg_receive($this->queue, $this->MSG_PUSH, $msgtype, ESTIMATED_BATCH_NAME_LENGTH * $this->config["BULK_MAX_BATCHES"], $message, true, 0, $errorcode)) { syslog(LOG_CRIT, "[push] Cannot pop from queue, sleeping: " . posix_strerror($errorcode)); $this->doSleep($this->config["FAILTIME"]); continue; } list($node, $batches) = $message; $dir = $this->config["BATCHDIR"] . "/push/{$node}"; $res = FALSE; while (!sem_acquire($this->sems[$node])) { syslog(LOG_INFO, "Cannot acquire lock for {$node}, retrying in " . $this->config["SCANTIME"]); $this->doSleep($this->config["FAILTIME"]); } try { if ($this->syncDataBatch($node, $batches, "push")) { $res = TRUE; } } catch (Exception $e) { syslog(LOG_CRIT, "Error while syncing {$node} {$batchFile}: " . print_r($e)); $res = FALSE; } if (!sem_release($this->sems[$node])) { syslog(LOG_CRIT, "Could not release lock for {$node}"); } if ($res && !$this->config["DRYRUN"]) { // unlink from push dir foreach ($batches as $batch) { $batchFile = "{$dir}/{$batch}"; if (!unlink($batchFile)) { syslog(LOG_CRIT, "Could not unlink {$batchFile}, will be retried"); $res = FALSE; } } unset($batchFile); } if ($res) { msg_send($this->queue, $this->MSG_RESULT, array($node, "success")); } else { msg_send($this->queue, $this->MSG_RESULT, array($node, "fail")); } } catch (Exception $e) { syslog(LOG_CRIT, "Worker loop: " . print_r($e, TRUE)); $this->doSleep($this->config["FAILTIME"]); } } }
<?php $folder = $_SERVER['DOCUMENT_ROOT'] . 'pf-2016/data'; $file_name = 'file_test.txt'; $file = $folder . '' . $file_name; if (posix_access($folder, POSIX_R_OK | POSIX_W_OK) && $_POST['data']) { $handler = fopen($file, 'a+'); $decode = json_decode($_POST['data'], true); // var_dump($_POST['data']); $addr = $_SERVER['DOCUMENT_ROOT'] . 'pf-2016/data/' . $decode['name'] . '.json'; // echo $addr; $file = fopen($addr, 'a+'); fwrite($file, $_POST['data']); fclose($file); echo '<div id="send_mail">message envoyé</div>'; } else { $error = posix_get_last_error(); echo 'Erreur ' . $error . ' :' . posix_strerror($error) . '<br />'; echo '</br />Contact Root for rights mofo<br />'; }
/** * Setup settings on start. * @return void */ protected function prepareSystemEnv() { proc_nice(Daemon::$config->workerpriority->value); register_shutdown_function(function () { $this->shutdown(true); }); $this->setTitle(Daemon::$runName . ': worker process' . (Daemon::$config->pidfile->value !== Daemon::$config->defaultpidfile->value ? ' (' . Daemon::$config->pidfile->value . ')' : '')); if (isset(Daemon::$config->group->value)) { $sg = posix_getgrnam(Daemon::$config->group->value); } if (isset(Daemon::$config->user->value)) { $su = posix_getpwnam(Daemon::$config->user->value); } $flushCache = false; if (Daemon::$config->chroot->value !== '/') { if (posix_getuid() != 0) { Daemon::log('You must have the root privileges to change root.'); exit(0); } elseif (!chroot(Daemon::$config->chroot->value)) { Daemon::log('Couldn\'t change root to \'' . Daemon::$config->chroot->value . '\'.'); exit(0); } $flushCache = true; } if (isset(Daemon::$config->group->value)) { if ($sg === FALSE) { Daemon::log('Couldn\'t change group to \'' . Daemon::$config->group->value . '\'. You must replace config-variable \'group\' with existing group.'); exit(0); } elseif ($sg['gid'] != posix_getgid() && !posix_setgid($sg['gid'])) { Daemon::log('Couldn\'t change group to \'' . Daemon::$config->group->value . "'. Error (" . ($errno = posix_get_last_error()) . '): ' . posix_strerror($errno)); exit(0); } $flushCache = true; } if (isset(Daemon::$config->user->value)) { if ($su === FALSE) { Daemon::log('Couldn\'t change user to \'' . Daemon::$config->user->value . '\', user not found. You must replace config-variable \'user\' with existing username.'); exit(0); } elseif ($su['uid'] != posix_getuid() && !posix_setuid($su['uid'])) { Daemon::log('Couldn\'t change user to \'' . Daemon::$config->user->value . "'. Error (" . ($errno = posix_get_last_error()) . '): ' . posix_strerror($errno)); exit(0); } $flushCache = true; } if ($flushCache) { clearstatcache(true); } if (Daemon::$config->cwd->value !== '.') { if (!@chdir(Daemon::$config->cwd->value)) { Daemon::log('Couldn\'t change directory to \'' . Daemon::$config->cwd->value . '.'); } clearstatcache(true); } }
public function updateStopTime($rec_id, $stop_time) { $pid_file = $this->getRecPidFile($rec_id); if (!is_file($pid_file)) { return true; } $pid = intval(file_get_contents($pid_file)); if (posix_kill($pid, 0)) { $kill_result = posix_kill($pid, 14); if (!$kill_result) { throw new IOException('Send signal to pid "' . $pid . '" failed on ' . $this->storage_name . ': ' . posix_strerror(posix_get_last_error())); } return $kill_result; } else { return true; } }
/** * * Shutdown function is call if script terminates try to make a restart if needed * * Prepare the job for start * * @internal param int the signal that terminates the job */ public function shutdown() { $args = func_get_args(); //Put last error to log if one $lasterror = error_get_last(); if ($lasterror['type'] == E_ERROR or $lasterror['type'] == E_PARSE or $lasterror['type'] == E_CORE_ERROR or $lasterror['type'] == E_CORE_WARNING or $lasterror['type'] == E_COMPILE_ERROR or $lasterror['type'] == E_COMPILE_WARNING) { $this->log($lasterror['type'], $lasterror['message'], $lasterror['file'], $lasterror['line']); } //Put signals to log if (!empty($args[0])) { $signals = array('SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGKILL', 'SIGSEGV', 'SIGPIPE', 'SIGALRM', 'SIGTERM', 'SIGSTKFLT', 'SIGUSR1', 'SIGUSR2', 'SIGCHLD', 'SIGCONT', 'SIGSTOP', 'SIGTSTP', 'SIGTTIN', 'SIGTTOU', 'SIGURG', 'SIGXCPU', 'SIGXFSZ', 'SIGVTALRM', 'SIGPROF', 'SIGWINCH', 'SIGIO', 'SIGPWR', 'SIGSYS'); foreach ($signals as $signal) { if (defined($signal) && $args[0] === constant($signal)) { $this->log(sprintf(__('Signal "%s" is sent to script!', 'backwpup'), $signal), E_USER_ERROR); break; } } } if (function_exists('pcntl_get_last_error')) { $error = pcntl_get_last_error(); if (!empty($error)) { $error_msg = pcntl_strerror($error); if (!empty($error_msg)) { $error = '(' . $error . ') ' . $error_msg; } } if (!empty($error)) { $this->log(sprintf(__('System: %s', 'backwpup'), $error), E_USER_ERROR); } } if (function_exists('posix_get_last_error') && empty($error)) { $error = posix_get_last_error(); if (!empty($error)) { $error_msg = posix_strerror($error); if (!empty($error_msg)) { $error = '(' . $error . ') ' . $error_msg; } } if (!empty($error)) { $this->log(sprintf(__('System: %s', 'backwpup'), $error), E_USER_ERROR); } } $this->do_restart(TRUE); }
$getgrgid = posix_getgrgid(25); // 25 is group floppy echo "getgrgid for group 25 =\n"; var_dump($getgrgid); $getpwnam = posix_getpwnam("ftp"); echo "getpwnam for user ftp =\n"; var_dump($getpwnam); $getpwuid = posix_getpwuid(106); // 106 is user ftp echo "getpwuid for userid 106 =\n"; var_dump($getpwuid); $getrlimit = posix_getrlimit(); echo "getrlimit=\n"; foreach ($getrlimit as $k => $v) { if (!($k === "soft stack")) { echo "fstat[{$k}] = {$v}\n"; } else { if ($v < 0) { echo "fstat[{$k}] is negative\n"; } else { echo "fstat[{$k}] is greater than or equal to 0\n"; } } } // test errno stuff $retval = posix_kill(-1, -1); $errno = posix_get_last_error(); $errstr = posix_strerror($errno); echo "posix_kill(-1, -1) returned {$retval}\n"; echo "posix_get_last_error({$retval}) returned {$errno}\n"; echo "posix_strerror({$errno}) returned {$errstr}\n";
VERIFY(posix_getpgrp()); VERIFY(posix_getpid()); VERIFY(posix_getppid()); $ret = posix_getpwnam("root"); VERIFY($ret != false); VERIFY(count((array) $ret) != 0); VS(posix_getpwnam(""), false); VS(posix_getpwnam(-1), false); $ret = posix_getpwuid(0); VERIFY($ret != false); VERIFY(count((array) $ret) != 0); VS(posix_getpwuid(-1), false); $ret = posix_getrlimit(); VERIFY($ret != false); VERIFY(count((array) $ret) != 0); VERIFY(posix_getsid(posix_getpid())); $tmpfifo = tempnam('/tmp', 'vmmkfifotest'); unlink($tmpfifo); VERIFY(posix_mkfifo($tmpfifo, 0)); $tmpnod = tempnam('/tmp', 'vmmknodtest'); unlink($tmpnod); VERIFY(posix_mknod($tmpnod, 0)); VERIFY(posix_setpgid(0, 0)); VERIFY(posix_setsid()); VERIFY(strlen(posix_strerror(1))); $ret = posix_times(); VERIFY($ret != false); VERIFY(count((array) $ret) != 0); $ret = posix_uname(); VERIFY($ret != false); VERIFY(count((array) $ret) != 0);
<?php /* Prototype : proto string posix_strerror(int errno) * Description: Retrieve the system error message associated with the given errno. * Source code: ext/posix/posix.c * Alias to functions: */ echo "*** Testing posix_strerror() : usage variations ***\n"; // Initialise function arguments not being substituted (if any) //get an unset variable $unset_var = 10; unset($unset_var); //array of values to iterate over $values = array(10.5, -10.5, 101234567000.0, 1.07654321E-9, 0.5, array(), array(0), array(1), array(1, 2), array('color' => 'red', 'item' => 'pen'), NULL, null, true, false, TRUE, FALSE, "", '', "string", 'string', $undefined_var, $unset_var, new stdclass()); // loop through each element of the array for errno foreach ($values as $value) { echo "\nArg value {$value} \n"; echo gettype(posix_strerror($value)) . "\n"; } echo "Done";
<?php echo "Basic test of POSIX times function\n"; $times = posix_times(); var_dump($times); if ($times == FALSE) { $errno = posix_get_last_error(); var_dump(posix_strerror($errno)); } ?> ===DONE====
/** * Retrieve the system error message associated with the given errno * * @param int $errno A POSIX error number, returned by * posix_get_last_error. If set to 0, then the * string "Success" is returned. * * @return string */ public function strerror(int $errno) : string { return posix_strerror($errno); }