本文整理匯總了PHP中Network::is_port_open方法的典型用法代碼示例。如果您正苦於以下問題:PHP Network::is_port_open方法的具體用法?PHP Network::is_port_open怎麽用?PHP Network::is_port_open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Network
的用法示例。
在下文中一共展示了Network::is_port_open方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ephimeral_port
/**
* Find an open port in a given range, trying several times.
* Return FALSE if no open port is found after a timeout (1 second by default)
*
* @param string $host
* @param integer $range_start
* @param integer $range_end
* @param integer $timeout
* @return integer|boolean
*/
public static function ephimeral_port($host, $range_start = 1000, $range_end = 5000, $timeout = 1000)
{
return Attempt::make(function () use($host, $range_start, $range_end) {
$port = rand($range_start, $range_end);
return Network::is_port_open($host, $port) ? $port : FALSE;
}, $timeout);
}
示例2: start
/**
* Start a phantomjs server in the background. Set port, server js file, additional files and log file.
*
* @param string $file the server js file
* @param integer $port the port to start the server on
* @param string $additional additional file, passed to the js server
* @param string $log_file
* @return string the pid of the newly started process
*/
public static function start($file, $port, $additional = NULL, $log_file = '/dev/null')
{
if (!Network::is_port_open('localhost', $port)) {
throw new Exception('Port :port is already taken', array(':port' => $port));
}
if ($log_file !== '/dev/null' and !is_file($log_file)) {
throw new Exception('Log file (:log_file) must be a file or /dev/null', array(':log_file' => $log_file));
}
return shell_exec(strtr('nohup :command > :log 2> :log & echo $!', array(':command' => self::command($file, $port, $additional), ':log' => $log_file)));
}
示例3: is_running
/**
* Check if the phantomjs server is actually running (the port is taken)
* @return boolean
*/
public function is_running()
{
return !Network::is_port_open($this->host(), $this->port());
}