本文整理汇总了PHP中socket_get_status函数的典型用法代码示例。如果您正苦于以下问题:PHP socket_get_status函数的具体用法?PHP socket_get_status怎么用?PHP socket_get_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了socket_get_status函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_data
/**
* Send request to VIES site and retrieve results
*
* @access public
* @param string
* @return mixed
*/
function load_data($url)
{
$url = parse_url($url);
if (!in_array($url['scheme'], array('', 'http'))) {
return false;
}
$fp = fsockopen($url['host'], $url['port'] > 0 ? $url['port'] : 80, $errno, $errstr, 2);
if (!$fp) {
return false;
} else {
fputs($fp, "GET " . $url['path'] . (isset($url['query']) ? '?' . $url['query'] : '') . " HTTP/1.0\r\n");
fputs($fp, "Host: " . $url['host'] . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
$data = '';
stream_set_blocking($fp, false);
stream_set_timeout($fp, 4);
$status = socket_get_status($fp);
while (!feof($fp) && !$status['timed_out']) {
$data .= fgets($fp, 1000);
$status = socket_get_status($fp);
}
if ($status['timed_out']) {
return false;
}
fclose($fp);
return $data;
}
}
示例2: _getResponse
private function _getResponse(&$r)
{
$r = '';
do {
$r .= fread($this->_fp, 1000);
$s = socket_get_status($this->_fp);
} while ($s['unread_bytes']);
}
示例3: bytes_left
function bytes_left($fp)
{
$status = socket_get_status($fp);
if ($status['unread_bytes'] > 0) {
return true;
}
return false;
}
示例4: get_url
function get_url($url, $timeout, $path, $querystring)
{
// Load the Lang file
if (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . strtolower($language) . '.php')) {
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . strtolower($language) . '.php';
} else {
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'english.php';
}
// Let PHP split the URL into parts
$parse_url = parse_url($url);
// Make sure the port is set
if (isset($parse_url['port']) && !empty($parse_url["port"])) {
$parse_url['port'] = ":" . $parse_url['port'];
}
// Define the path
$path = $path . $querystring;
// Init var which contains method used
$method = "";
if (function_exists("curl_exec")) {
$method = "curl_exec";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $parse_url['scheme'] . "://" . $parse_url['host'] . $parse_url["port"] . $path);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
$errstr = curl_error($ch);
curl_close($ch);
} else {
$method = "fsockopen";
$fp = fsockopen($url, $parse_url["port"], $errno, $errstr, $timeout);
if ($fp) {
$header = "GET " . $path . " HTTP/1.0\r\n";
$header .= "Host: " . $parse_url['host'] . "\r\n";
$header .= "Content-type: text/html\r\n";
$header .= "Connection: close\r\n\r\n";
$data = "";
@stream_set_timeout($fp, $timeout);
@fputs($fp, $header);
$status = @socket_get_status($fp);
while (!@feof($fp) && $status) {
$data .= @fgets($fp, 1024);
$status = @socket_get_status($fp);
}
@fclose($fp);
}
}
// Return success, and data or error
if (!$data) {
return array("success" => false, "data" => "{$_ADDONLANG['client_connection_failed']} (" . $method . ":" . $errstr . ")");
} else {
return array("success" => true, "data" => $data);
}
}
示例5: getResponse
/**
* Read the output
* @return string
*/
function getResponse()
{
$r = '';
do {
$r .= fread($this->socket, 1000);
usleep($this->sleeptime);
$s = socket_get_status($this->socket);
} while ($s['unread_bytes']);
//usleep($this->sleeptime);
return $r;
}
示例6: SetDataAccessError
function SetDataAccessError($error)
{
$this->error = $error;
if (function_exists("socket_get_status")) {
$status = socket_get_status($this->connection);
if ($status["timed_out"]) {
$this->error .= ": data access time out";
} elseif ($status["eof"]) {
$this->error .= ": the server disconnected";
}
}
}
示例7: opened
public function opened()
{
if (!empty($this->socket)) {
$status = socket_get_status($this->socket);
if ($status['eof']) {
$this->close();
return false;
}
return true;
}
return false;
}
示例8: mail_connected
function mail_connected()
{
if (!empty($this->mail_connection)) {
$sock_status = @socket_get_status($this->mail_connection);
if ($sock_status["eof"]) {
@fclose($this->mail_connection);
return 0;
}
return 1;
}
return 0;
}
示例9: test_return
function test_return($res, &$error)
{
$out = fread($res, 1);
$len = socket_get_status($res);
if ($len > 0) {
$out .= fread($res, $len['unread_bytes']);
}
//echo $out;
if (preg_match("/^5/", $out)) {
$error = $out;
return false;
}
return true;
}
示例10: Connected
public function Connected()
{
if (!empty($this->smtp_conn)) {
$sock_status = socket_get_status($this->smtp_conn);
if ($sock_status["eof"]) {
if ($this->do_debug >= 1) {
echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
}
$this->Close();
return false;
}
return true;
}
return false;
}
示例11: socketStatus
/**
* Checks a socket for timeout or EOF
* @param int socket handle
* @return boolean true if the socket has timed out or is EOF
*/
function socketStatus(&$fh)
{
$return = false;
if (is_resource($fh)) {
$temp = socket_get_status($fh);
if ($temp['timed_out']) {
$return = true;
}
if ($temp['eof']) {
$return = true;
}
unset($temp);
}
return $return;
}
示例12: weblogUpdates_ping
function weblogUpdates_ping($host, $port, $path, $method, $name, $url, $debug = false)
{
$postdata = '<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>' . htmlspecialchars($method) . '</methodName>
<params>
<param><value><string>' . htmlspecialchars($name) . '</string></value></param>
<param><value><string>' . htmlspecialchars($url) . '</string></value></param>
</params>
</methodCall>';
$timeout = 20;
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
if (!$fp) {
return array(-1, "Could not connect to {$host}:{$port}");
}
socket_set_timeout($fp, $timeout);
$request = "POST {$path} HTTP/1.0\r\n" . "Host: {$host}\r\n" . "Content-Type: text/xml\r\n" . "User-Agent: Aggemam XML-RPC client\r\n" . "Content-Length: " . strlen($postdata) . "\r\n" . "\r\n" . $postdata;
fputs($fp, $request);
if ($debug) {
print "<div style='color: blue; white-space: pre'>";
print htmlspecialchars($request);
print "</div>";
}
$response = '';
while (!feof($fp)) {
$response .= fgets($fp, 1024);
$status = socket_get_status($fp);
if ($status['timed_out']) {
fclose($fp);
return array(-2, "Request timed out");
}
}
fclose($fp);
if ($debug) {
print "<div style='color: green; white-space: pre'>";
print htmlspecialchars($response);
print "</div>";
}
if (preg_match('|<methodResponse>\\s*<params>\\s*<param>\\s*<value>\\s*<struct>\\s*' . '<member>\\s*<name>flerror</name>\\s*<value>\\s*<boolean>([^<])</boolean>\\s*</value>\\s*</member>\\s*' . '<member>\\s*<name>message</name>\\s*<value>(\\s*<string>)?([^<]*)(</string>\\s*)?</value>\\s*</member>\\s*' . '</struct>\\s*</value>\\s*</param>\\s*</params>\\s*</methodResponse>' . '|s', $response, $reg)) {
return array($reg[1], $reg[3]);
} else {
return array(-3, "Malformed reply:\n" . $response);
}
}
示例13: fsock_get_contents
//.........这里部分代码省略.........
if (!empty($ua)) {
$query .= "User-Agent: " . $ua . "\r\n";
}
if (!is_null($getSize)) {
$query .= 'Range: bytes=0-' . ($getSize - 1) . "\r\n";
}
$query .= $headers;
$query .= "\r\n";
$fp = $connect_try_count = 0;
while (!$fp && $connect_try_count < $connect_try) {
$errno = 0;
$errstr = "";
$fp = @fsockopen($arr['https'] . $arr['host'], $arr['port'], $errno, $errstr, $connect_timeout);
if ($fp) {
break;
}
$connect_try_count++;
if (connection_aborted()) {
exit;
}
sleep(1);
// wait 1sec
}
$fwrite = 0;
for ($written = 0; $written < strlen($query); $written += $fwrite) {
$fwrite = fwrite($fp, substr($query, $written));
if (!$fwrite) {
break;
}
}
$response = '';
if ($timeout) {
socket_set_timeout($fp, $timeout);
}
$_response = '';
$header = '';
while ($_response !== "\r\n") {
$_response = fgets($fp, $readsize);
$header .= $_response;
}
$rccd = array_pad(explode(' ', $header, 3), 3, '');
// array('HTTP/1.1','200','OK\r\n...')
$rc = (int) $rccd[1];
// Redirect
switch ($rc) {
case 307:
// Temporary Redirect
// Temporary Redirect
case 303:
// See Other
// See Other
case 302:
// Moved Temporarily
// Moved Temporarily
case 301:
// Moved Permanently
$matches = array();
if (preg_match('/^Location: (.+?)(#.+)?$/im', $header, $matches) && --$redirect_max > 0) {
$url = trim($matches[1]);
$hash = isset($matches[2]) ? trim($matches[2]) : '';
if (!preg_match('/^https?:\\//', $url)) {
// no scheme
if ($url[0] != '/') {
// Relative path
// to Absolute path
$url = substr($url_path, 0, strrpos($url_path, '/')) . '/' . $url;
}
// add sheme,host
$url = $url_base . $url;
}
fclose($fp);
return $this->fsock_get_contents($url, $timeout, $redirect_max, $ua, $outfp);
}
}
$body = '';
if (!$outfp) {
$outfp = fopen('php://temp', 'rwb');
$body = true;
}
while (fwrite($outfp, fread($fp, $readsize))) {
if ($timeout) {
$_status = socket_get_status($fp);
if ($_status['timed_out']) {
fclose($outfp);
fclose($fp);
return false;
// Request Time-out
}
}
}
if ($body) {
rewind($outfp);
$body = stream_get_contents($outfp);
fclose($outfp);
$outfp = null;
}
fclose($fp);
return $outfp ? $outfp : $body;
// Data
}
示例14: exec
public function exec($force_connection_method = GATEWAY_NO_FORCE)
{
if ($force_connection_method != GATEWAY_FORCE_SOCKET && self::isCurlAvailable()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$this->_scheme}://{$this->_host}" . (!is_null($this->_port) ? ':' . $this->_port : NULL) . $this->_path);
curl_setopt($ch, CURLOPT_HEADER, $this->_returnHeaders);
curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent);
curl_setopt($ch, CURLOPT_PORT, $this->_port);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_COOKIEJAR, TMP . '/cookie.txt');
@curl_setopt($ch, CURLOPT_COOKIEFILE, TMP . '/cookie.txt');
curl_setopt($ch, CURLOPT_TIMEOUT, $this->_timeout);
if ($this->_method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_postfields);
}
if (is_array($this->_custom_opt) && !empty($this->_custom_opt)) {
foreach ($this->_custom_opt as $opt => $value) {
curl_setopt($ch, $opt, $value);
}
}
##Grab the result
$result = curl_exec($ch);
$this->_info_last = curl_getinfo($ch);
##Close the connection
curl_close($ch);
return $result;
}
##No CURL is available, use attempt to use normal sockets
if (!($handle = fsockopen($this->_host, $this->_port, $errno, $errstr, $this->_timeout))) {
return false;
} else {
$query = $this->_method . ' ' . $this->_path . ' HTTP/' . $this->_http_version . self::CRLF;
$query .= 'Host: ' . $this->_host . self::CRLF;
$query .= 'Content-type: ' . $this->_content_type . self::CRLF;
$query .= 'User-Agent: ' . $this->_agent . self::CRLF;
$query .= @implode(self::CRLF, $this->_headers);
$query .= 'Content-length: ' . strlen($this->_postfields) . self::CRLF;
$query .= 'Connection: close' . self::CRLF . self::CRLF;
if ($this->_method == 'POST') {
$query .= $this->_postfields;
}
// send request
if (!@fwrite($handle, $query)) {
return false;
}
stream_set_blocking($handle, false);
stream_set_timeout($handle, $this->_timeout);
$status = stream_get_meta_data($handle);
// get header
while (!preg_match('/\\r\\n\\r\\n$/', $header) && !$status['timed_out']) {
$header .= @fread($handle, 1);
$status = stream_get_meta_data($handle);
}
$status = socket_get_status($handle);
## Get rest of the page data
while (!feof($handle) && !$status['timed_out']) {
$response .= fread($handle, 4096);
$status = stream_get_meta_data($handle);
}
@fclose($handle);
if (preg_match('/Transfer\\-Encoding:\\s+chunked\\r\\n/', $header)) {
$fp = 0;
do {
$byte = '';
$chunk_size = '';
do {
$chunk_size .= $byte;
$byte = substr($response, $fp, 1);
$fp++;
} while ($byte != "\r" && $byte != "\\r");
$chunk_size = hexdec($chunk_size);
// convert to real number
if ($chunk_size == 0) {
break 1;
}
$fp++;
$dechunked .= substr($response, $fp, $chunk_size);
$fp += $chunk_size;
$fp += 2;
} while (true);
$response = $dechunked;
}
}
// Following code emulates part of the function curl_getinfo()
preg_match('/Content-Type:\\s*([^\\r\\n]+)/i', $header, $match);
$content_type = $match[1];
preg_match('/HTTP\\/\\d+.\\d+\\s+(\\d+)/i', $header, $match);
$status = $match[1];
$this->_info_last = array('url' => $this->_url, 'content_type' => $content_type, 'http_code' => $status);
return ($this->_returnHeaders ? $header : NULL) . $response;
}
示例15: smart_udp_read
/**
* Smart UDP Read
*
* Face it, when it comes to reading UDP packets, PHP is rather dumb
* This gives us a slightly smarter udp read that waits for the socket to be unblocked
* and keeps reading until there's no more waiting data.
*
* @throws Exception
* @return string
*/
protected function smart_udp_read()
{
if (!$this->socket) {
throw new Exception('Socket not opened');
}
$string_length = $timer = 0;
$data = '';
// Wait for the socket to be ready and the data to appear - until classic_timeout
while (strlen($data) == 0) {
if ($timer < $this->classic_timeout) {
$data .= fgets($this->socket, 2);
usleep(1);
$timer++;
} else {
return 0;
}
}
// Keep reading until the length recorded matches the actual length - in hopes
// that unread_bytes will keep up :)
while ($string_length < strlen($data)) {
$socket_status = socket_get_status($this->socket);
$string_length = strlen($data);
$data .= fgets($this->socket, $socket_status['unread_bytes'] + 1);
}
return $data;
}