• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP posix_get_last_error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中posix_get_last_error函数的典型用法代码示例。如果您正苦于以下问题:PHP posix_get_last_error函数的具体用法?PHP posix_get_last_error怎么用?PHP posix_get_last_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了posix_get_last_error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: error

 /**
  *	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());
 }
开发者ID:evilgeny,项目名称:bob,代码行数:12,代码来源:File.class.php


示例2: __construct

 /**
  * Initializes exception.
  *
  * @param string $message Error message.
  * @param int $code Error code.
  * @param \Exception $previous Previous exception.
  * @version 0.0.1
  * @since 0.0.1
  */
 public function __construct($message = null, $code = null, \Exception $previous = null)
 {
     // detect POSIX error info
     $code = isset($code) ? $code : \posix_get_last_error();
     $message = isset($message) ? $message : \posix_strerr($code);
     parent::__construct($message, $code, $previous);
 }
开发者ID:adispartadev,项目名称:Pork,代码行数:16,代码来源:PosixException.php


示例3: handleStop

 protected function handleStop()
 {
     $pidFile = APPLICATION_PATH . '/runtime/jobserver.pid';
     if (file_exists($pidFile)) {
         $pids = explode("|", file_get_contents($pidFile));
         $del = 1;
         foreach ($pids as $pid) {
             $rs = posix_kill($pid, 15);
             if (!$rs) {
                 $del = 0;
                 echo "del_fail\r\n";
                 print_r(posix_get_last_error());
                 echo "\r\n";
             }
         }
         if ($del) {
             echo "del_ok\r\n";
             print_r(posix_get_last_error());
             echo "\r\n";
             do {
                 unlink($pidFile);
                 usleep(100000);
             } while (file_exists($pidFile));
             return 0;
         }
     }
     return 1;
 }
开发者ID:kerisy,项目名称:framework,代码行数:28,代码来源:JobServerCommand.php


示例4: __construct

 /**
  * 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));
         }
     }
 }
开发者ID:gcds,项目名称:morker,代码行数:36,代码来源:Fifo.php


示例5: tryStart

 /**
  * 尝试开始任务
  *
  * @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;
 }
开发者ID:tempbottle,项目名称:owl,代码行数:40,代码来源:Crontab.php


示例6: open

 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);
 }
开发者ID:a13k5and3r,项目名称:Stream,代码行数:26,代码来源:NamedPipe.php


示例7: daemonize

 /**
  * 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;
 }
开发者ID:nexxes,项目名称:php-daemonhelper,代码行数:41,代码来源:Daemon.php


示例8: setUid

 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()));
     }
 }
开发者ID:panlatent,项目名称:aurora,代码行数:10,代码来源:Posix.php


示例9: kill_concentrator

 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");
     }
 }
开发者ID:giant-rabbit,项目名称:mysql-concentrator,代码行数:14,代码来源:test.php


示例10: wait

 /**
  * 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}");
         }
     }
 }
开发者ID:ablyler,项目名称:phan,代码行数:19,代码来源:ForkPool.php


示例11: __getpid

function __getpid()
{
    $pid_file = '/tmp/swoole.pid';
    if (defined('SWOOLE_PID')) {
        $pid_file = SWOOLE_PID;
    }
    $pid = file_exists($pid_file) ? file_get_contents($pid_file) : 0;
    // 检查进程是否真正存在
    if ($pid && !posix_kill($pid, 0)) {
        $errno = posix_get_last_error();
        if ($errno === 3) {
            $pid = 0;
        }
    }
    return $pid;
}
开发者ID:cloklo,项目名称:CxWoole,代码行数:16,代码来源:server.php


示例12: __construct

 /**
  * @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);
 }
开发者ID:nagyistge,项目名称:phan,代码行数:64,代码来源:ForkPool.php


示例13: isProcessRunning

 public static function isProcessRunning($pid)
 {
     if (!$pid) {
         return false;
     }
     // This may fail if we can't signal the process because we are running as
     // a different user (for example, we are 'apache' and the process is some
     // other user's, or we are a normal user and the process is root's), but
     // we can check the error code to figure out if the process exists.
     $is_running = posix_kill($pid, 0);
     if (posix_get_last_error() == 1) {
         // "Operation Not Permitted", indicates that the PID exists. If it
         // doesn't, we'll get an error 3 ("No such process") instead.
         $is_running = true;
     }
     return $is_running;
 }
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:17,代码来源:PhabricatorDaemonReference.php


示例14: stop

 public function stop()
 {
     if (!$this->getPid()) {
         throw new \Exception("Process not running");
     }
     foreach (range(1, 10) as $i) {
         switch ($i) {
             case 1:
                 $this->logger->debug('Sending SIGTERM');
                 posix_kill($this->getPid(), SIGTERM);
                 if (posix_get_last_error() == SOCKET_EPERM) {
                     throw new \Exception("You do not have permission to stop this process");
                 }
                 if ($this->status() != self::RUNNING_OK) {
                     $this->logger->debug('First attempt results in full stop!');
                     break 2;
                 }
                 break;
             case 10:
                 $this->logger->debug('Sending SIGKILL!!');
                 posix_kill($this->getPid(), SIGKILL);
                 if ($this->status() != self::RUNNING_OK) {
                     $this->logger->debug('Results in full stop!');
                     break 2;
                 }
                 break;
             default:
                 $this->logger->debug('Sending another SIGTERM');
                 posix_kill($this->getPid(), SIGTERM);
                 if ($this->status() != self::RUNNING_OK) {
                     $this->logger->debug('Results in full stop!');
                     break 2;
                 }
                 break;
         }
         sleep(3);
     }
     if ($this->status() == self::RUNNING_OK) {
         throw new \Exception("There was an error attempting to end the process");
     }
     $this->clearPid();
 }
开发者ID:dcousineau,项目名称:phorever,代码行数:42,代码来源:Daemon.php


示例15: action_exit

 public function action_exit()
 {
     if (file_exists($this->_config['pid_path'])) {
         $pid = file_get_contents($this->_config['pid_path']);
         if ($pid !== 0) {
             Kohana::$log->add('debug', 'Sending SIGTERM to pid ' . $pid);
             echo 'Sending SIGTERM to pid ' . $pid . PHP_EOL;
             posix_kill($pid, SIGTERM);
             if (posix_get_last_error() === 0) {
                 echo "Signal send SIGTERM to pid " . $pid . PHP_EOL;
             } else {
                 echo "An error occured while sending SIGTERM" . PHP_EOL;
                 unlink($this->_config['pid_path']);
             }
         } else {
             Kohana::$log->add("debug", "Could not find MangoQueue pid in file :" . $this->_config['pid_path']);
             echo "Could not find task_queue pid in file :" . $this->_config['pid_path'] . PHP_EOL;
         }
     } else {
         Kohana::$log->add("error", "MangoQueue pid file " . $this->_config['pid_path'] . " does not exist");
         echo "MangoQueue pid file " . $this->_config['pid_path'] . " does not exist" . PHP_EOL;
     }
 }
开发者ID:praxxis,项目名称:mangoQueue,代码行数:23,代码来源:daemon.php


示例16: posix_times

<?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====
开发者ID:badlamer,项目名称:hhvm,代码行数:11,代码来源:posix_times_basic.php


示例17: closeTunnel

 /**
  * Close an open tunnel.
  *
  * @param array $tunnel
  *
  * @return bool
  *   True on success, false on failure.
  */
 protected function closeTunnel(array $tunnel)
 {
     $success = true;
     if (isset($tunnel['pid']) && function_exists('posix_kill')) {
         $success = posix_kill($tunnel['pid'], SIGTERM);
         if (!$success) {
             $this->stdErr->writeln(sprintf('Failed to kill process <error>%d</error> (POSIX error %s)', $tunnel['pid'], posix_get_last_error()));
         }
     }
     $pidFile = $this->getPidFile($tunnel);
     if (file_exists($pidFile)) {
         $success = unlink($pidFile) && $success;
     }
     $this->tunnelInfo = array_filter($this->tunnelInfo, function ($info) use($tunnel) {
         return !$this->tunnelsAreEqual($info, $tunnel);
     });
     $this->saveTunnelInfo();
     return $success;
 }
开发者ID:commerceguys,项目名称:platform-cli,代码行数:27,代码来源:TunnelCommandBase.php


示例18: stdapi_sys_process_kill

 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;
 }
开发者ID:Ebrietas0,项目名称:metasploit-framework,代码行数:28,代码来源:ext_server_stdapi.php


示例19: shutdown

 /**
  *
  * 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);
 }
开发者ID:skinnard,项目名称:FTL-2,代码行数:42,代码来源:class-job.php


示例20: terminate_proc

 /**
  * 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);
 }
开发者ID:Ryan4021,项目名称:wp-rest-cli,代码行数:21,代码来源:FeatureContext.php



注:本文中的posix_get_last_error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP posix_getegid函数代码示例发布时间:2022-05-15
下一篇:
PHP position函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap