当前位置: 首页>>代码示例>>PHP>>正文


PHP posix_strerror函数代码示例

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


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

示例1: __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

示例2: 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

示例3: 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

示例4: 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

示例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: 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

示例7: 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

示例8: 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

示例9: __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

示例10: posix_get_last_error

<?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);
}
开发者ID:exakat,项目名称:exakat,代码行数:9,代码来源:Extposix.01.php

示例11: posix_strerror

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

示例12: posixError

 /**
  * @return TransportException
  */
 public static function posixError()
 {
     return new self(sprintf('Posix error [%s]: "%s"', posix_get_last_error(), posix_strerror(posix_get_last_error())));
 }
开发者ID:pbergman,项目名称:fifo,代码行数:7,代码来源:TransportException.php

示例13: strerror

 /**
  * 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);
 }
开发者ID:dantudor,项目名称:posix,代码行数:11,代码来源:Posix.php

示例14: killProcessAndChilds

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));
    }
}
开发者ID:sni,项目名称:webmp3,代码行数:21,代码来源:common.php

示例15: 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


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