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


PHP socket_set_option函数代码示例

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


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

示例1: http_request

 function http_request($host, $data)
 {
     if (!($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
         echo "socket_create() error!\r\n";
         exit;
     }
     if (!socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1)) {
         echo "socket_set_option() error!\r\n";
         exit;
     }
     if (!socket_connect($socket, $host, 80)) {
         echo "socket_connect() error!\r\n";
         exit;
     }
     if (!socket_write($socket, $data, strlen($data))) {
         echo "socket_write() errror!\r\n";
         exit;
     }
     while ($get = socket_read($socket, 1024, PHP_NORMAL_READ)) {
         $content .= $get;
     }
     socket_close($socket);
     $array = array('HTTP/1.1 404 Not Found', 'HTTP/1.1 300 Multiple Choices', 'HTTP/1.1 301 Moved Permanently', 'HTTP/1.1 302 Found', 'HTTP/1.1 304 Not Modified', 'HTTP/1.1 400 Bad Request', 'HTTP/1.1 401 Unauthorized', 'HTTP/1.1 402 Payment Required', 'HTTP/1.1 403 Forbidden', 'HTTP/1.1 405 Method Not Allowed', 'HTTP/1.1 406 Not Acceptable', 'HTTP/1.1 407 Proxy Authentication Required', 'HTTP/1.1 408 Request Timeout', 'HTTP/1.1 409 Conflict', 'HTTP/1.1 410 Gone', 'HTTP/1.1 411 Length Required', 'HTTP/1.1 412 Precondition Failed', 'HTTP/1.1 413 Request Entity Too Large', 'HTTP/1.1 414 Request-URI Too Long', 'HTTP/1.1 415 Unsupported Media Type', 'HTTP/1.1 416 Request Range Not Satisfiable', 'HTTP/1.1 417 Expectation Failed', 'HTTP/1.1 Retry With');
     for ($i = 0; $i <= count($array); $i++) {
         if (eregi($array[$i], $content)) {
             return "{$array[$i]}\r\n";
             break;
         } else {
             return "{$content}\r\n";
             break;
         }
     }
 }
开发者ID:SuperQcheng,项目名称:exploit-database,代码行数:33,代码来源:7031.php

示例2: flushAll

 /**
  * {@inheritdoc}
  */
 public function flushAll()
 {
     if ($this->currentOnly) {
         return apc_clear_cache('user') && apc_clear_cache();
     }
     $result = true;
     foreach ($this->servers as $server) {
         if (count(explode('.', $server['ip'])) == 3) {
             $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
         } else {
             $socket = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
         }
         // generate the raw http request
         $command = sprintf("GET %s HTTP/1.1\r\n", $this->getUrl());
         $command .= sprintf("Host: %s\r\n", $server['domain']);
         if ($server['basic']) {
             $command .= sprintf("Authorization: Basic %s\r\n", $server['basic']);
         }
         $command .= "Connection: Close\r\n\r\n";
         // setup the default timeout (avoid max execution time)
         socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 2, 'usec' => 0));
         socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 2, 'usec' => 0));
         socket_connect($socket, $server['ip'], $server['port']);
         socket_write($socket, $command);
         $content = '';
         do {
             $buffer = socket_read($socket, 1024);
             $content .= $buffer;
         } while (!empty($buffer));
         if ($result) {
             $result = substr($content, -2) == 'ok';
         }
     }
     return $result;
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:38,代码来源:ApcCache.php

示例3: wol

 function wol($host, $mac)
 {
     //get the broadcast addr
     $range = $this->iprange($host, 24);
     $broadcast = $range['last_ip'];
     $mac_array = explode(':', $mac);
     $hwaddr = '';
     foreach ($mac_array as $octet) {
         $hwaddr .= chr(hexdec($octet));
     }
     // Create Magic Packet
     $packet = '';
     for ($i = 1; $i <= 6; $i++) {
         $packet .= chr(255);
     }
     for ($i = 1; $i <= 16; $i++) {
         $packet .= $hwaddr;
     }
     $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     if ($sock) {
         $options = socket_set_option($sock, 1, 6, true);
         if ($options >= 0) {
             $e = socket_sendto($sock, $packet, strlen($packet), 0, $broadcast, 9);
             socket_close($sock);
         }
     }
 }
开发者ID:robweber,项目名称:simple-inventory,代码行数:27,代码来源:PingComponent.php

示例4: __construct

 function __construct($options)
 {
     $this->reset($options);
     pcntl_signal(SIGTERM, array("JAXLHTTPd", "shutdown"));
     pcntl_signal(SIGINT, array("JAXLHTTPd", "shutdown"));
     $options = getopt("p:b:");
     foreach ($options as $opt => $val) {
         switch ($opt) {
             case 'p':
                 $this->settings['port'] = $val;
                 break;
             case 'b':
                 $this->settings['maxq'] = $val;
             default:
                 break;
         }
     }
     $this->httpd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     socket_set_option($this->httpd, SOL_SOCKET, SO_REUSEADDR, 1);
     socket_bind($this->httpd, 0, $this->settings['port']);
     socket_listen($this->httpd, $this->settings['maxq']);
     $this->id = $this->getResourceID($this->httpd);
     $this->clients = array("0#" . $this->settings['port'] => $this->httpd);
     echo "JAXLHTTPd listening on port " . $this->settings['port'] . PHP_EOL;
 }
开发者ID:pavl00,项目名称:Kalkun,代码行数:25,代码来源:jaxl.httpd.php

示例5: flushAll

 public function flushAll()
 {
     $result = true;
     foreach ($this->servers as $server) {
         if (count(explode('.', $server['ip']) == 3)) {
             $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
         } else {
             $socket = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
         }
         // generate the raw http request
         $command = sprintf("GET %s HTTP/1.1\r\n", $this->router->generate('sonata_page_apc_cache', array('token' => $this->token)));
         $command .= sprintf("Host: %s\r\n", $server['domain']);
         $command .= "Connection: Close\r\n\r\n";
         // setup the default timeout (avoid max execution time)
         socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 2, 'usec' => 0));
         socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 2, 'usec' => 0));
         socket_connect($socket, $server['ip'], $server['port']);
         socket_write($socket, $command);
         $content = socket_read($socket, 1024);
         if ($result) {
             $result = substr($content, -2) == 'ok' ? true : false;
         }
     }
     return $result;
 }
开发者ID:norfil,项目名称:SonataPageBundle,代码行数:25,代码来源:ApcCache.php

示例6: __construct

 public function __construct($host, $port)
 {
     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     socket_connect($this->socket, $host, $port);
     socket_set_option($this->socket, SOL_TCP, 1, 1);
     //socket_set_option ( $this->socket, SOL_TCP, SO_SNDBUF, 1024 * 1024 );
 }
开发者ID:js-wei,项目名称:Wechat,代码行数:7,代码来源:BigEndianSocketBuffer.php

示例7: _openConnection

 private function _openConnection($debug = null)
 {
     $connection = false;
     if (function_exists('socket_create') && function_exists('socket_connect') && function_exists('socket_strerror') && function_exists('socket_last_error') && function_exists('socket_set_block') && function_exists('socket_read') && function_exists('socket_write') && function_exists('socket_close')) {
         $this->_sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
         if (function_exists('socket_set_option')) {
             socket_set_option($this->_sock, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 5, 'usec' => 0]);
             socket_set_option($this->_sock, SOL_SOCKET, SO_SNDTIMEO, ['sec' => 5, 'usec' => 0]);
         }
         @($connection = socket_connect($this->_sock, $this->_serverIP, $this->_serverRconQueryPort));
         if ($debug == '-d') {
             echo '[DEBUG]: ' . socket_strerror(socket_last_error()) . ".\n";
         }
         if ($connection) {
             socket_set_block($this->_sock);
         }
         $this->_sockType = 1;
     } else {
         if (function_exists('fsockopen')) {
             if ($debug == '-d') {
                 @($this->_sock = fsockopen('tcp://' . $this->_serverIP, $this->_serverRconQueryPort, $errno, $errstr, 10));
                 if (!$this->_sock) {
                     echo '[DEBUG]: ' . $errno . ' - ' . $errstr . "\n";
                 }
             } else {
                 @($this->_sock = fsockopen('tcp://' . $this->_serverIP, $this->_serverRconQueryPort));
             }
             $connection = $this->_sock;
             $this->_sockType = 2;
         }
     }
     return $connection;
 }
开发者ID:BP4U,项目名称:BFAdminCP,代码行数:33,代码来源:BF4Conn.php

示例8: WakeOnLan

function WakeOnLan($addr, $mac_address, $socket_number)
{
    $addr_byte = explode(':', $mac_address);
    $hw_addr = '';
    for ($a = 0; $a < 6; $a++) {
        $hw_addr .= chr(hexdec($addr_byte[$a]));
        $msg = chr(255) . chr(255) . chr(255) . chr(255) . chr(255) . chr(255);
        for ($a = 1; $a <= 16; $a++) {
            $msg .= $hw_addr;
            // send it to the broadcast address using UDP
            // SQL_BROADCAST option isn't help!!
            $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
            if ($s == false) {
                echo "Error creating socket!\n";
                echo "Error code is '" . socket_last_error($s) . "' - " . socket_strerror(socket_last_error($s));
                return FALSE;
            } else {
                // setting a broadcast option to socket:
                $opt_ret = socket_set_option($s, 1, 6, TRUE);
                if ($opt_ret < 0) {
                    echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
                    return FALSE;
                }
                if (socket_sendto($s, $msg, strlen($msg), 0, $ip_address, $socket_number)) {
                    echo "Magic Packet sent successfully!";
                    socket_close($s);
                    return TRUE;
                } else {
                    echo "Magic packet failed!";
                    return FALSE;
                }
            }
        }
    }
}
开发者ID:guille-phillips,项目名称:vb6misc,代码行数:35,代码来源:wake_on_lan.php

示例9: search

 public function search($st = 'ssdp:all', $mx = 2, $man = 'ssdp:discover', $from = null, $port = null, $sockTimout = '2')
 {
     $request = 'M-SEARCH * HTTP/1.1' . "\r\n";
     $request .= 'HOST: 239.255.255.250:1900' . "\r\n";
     $request .= 'MAN: "' . $man . '"' . "\r\n";
     $request .= 'MX: ' . $mx . '' . "\r\n";
     $request .= 'ST: ' . $st . '' . "\r\n";
     $request .= 'USER-AGENT: ' . $this->user_agent . "\r\n";
     $request .= "\r\n";
     $socket = socket_create(AF_INET, SOCK_DGRAM, 0);
     socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, true);
     socket_sendto($socket, $request, strlen($request), 0, '239.255.255.250', 1900);
     socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockTimout, 'usec' => '0'));
     $response = array();
     do {
         $buf = null;
         socket_recvfrom($socket, $buf, 1024, MSG_WAITALL, $from, $port);
         if (!is_null($buf)) {
             $data = $this->parseSearchResponse($buf);
             $response[$data['usn']] = $data;
         }
     } while (!is_null($buf));
     socket_close($socket);
     return $response;
 }
开发者ID:T-REX-XP,项目名称:UPnP,代码行数:25,代码来源:Core.php

示例10: connect

 /**
  * Gets the OrientSocket, and establishes the connection if required.
  *
  * @return \PhpOrient\Protocols\Binary\OrientSocket
  *
  * @throws SocketException
  * @throws PhpOrientWrongProtocolVersionException
  */
 public function connect()
 {
     if (!$this->connected) {
         if (empty($this->hostname) && empty($this->port)) {
             throw new SocketException('Can not initialize a connection ' . 'without connection parameters');
         }
         if (!extension_loaded("sockets")) {
             throw new SocketException('Can not initialize a connection ' . 'without socket extension enabled. Please check you php.ini');
         }
         $this->_socket = @socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
         socket_set_block($this->_socket);
         socket_set_option($this->_socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => self::READ_TIMEOUT, 'usec' => 0));
         socket_set_option($this->_socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => self::WRITE_TIMEOUT, 'usec' => 0));
         $x = @socket_connect($this->_socket, $this->hostname, $this->port);
         if (!is_resource($this->_socket) || $x === false) {
             throw new SocketException($this->getErr() . PHP_EOL);
         }
         $protocol = Reader::unpackShort($this->read(2));
         if ($protocol > $this->protocolVersion) {
             throw new PhpOrientWrongProtocolVersionException('Protocol version ' . $protocol . ' is not supported.');
         }
         //protocol handshake
         $this->protocolVersion = $protocol;
         $this->connected = true;
     }
     return $this;
 }
开发者ID:emman-ok,项目名称:PhpOrient,代码行数:35,代码来源:OrientSocket.php

示例11: create_connection

function create_connection($host, $port)
{
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if (!is_resource($socket)) {
        echo 'Unable to create socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
    } else {
        echo "Socket created.\n";
    }
    if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
        echo 'Unable to set option on socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
    } else {
        echo "Set options on socket.\n";
    }
    if (!socket_bind($socket, $host, $port)) {
        echo 'Unable to bind socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
    } else {
        echo "Socket bound to port {$port}.\n";
    }
    if (!socket_listen($socket, SOMAXCONN)) {
        echo 'Unable to listen on socket: ' . socket_strerror(socket_last_error());
    } else {
        echo "Listening on the socket.\n";
    }
    while (true) {
        $connection = @socket_accept($socket);
        if ($connection) {
            echo "Client {$connection} connected!\n";
            send_data($connection);
        } else {
            echo "Bad connection.";
        }
    }
}
开发者ID:ryanstewart,项目名称:PHP-Socket-Demo,代码行数:33,代码来源:socket_quotes.php

示例12: commit

 public function commit($intLogID, $strQueueName, $strOperation, $arrOperationBody)
 {
     if ($this->_check_conntect()) {
         $sendArray = array();
         $sendArray['__QUEUE_NAME__'] = $strQueueName;
         $sendArray['__OPERATION__'] = $strOperation;
         $sendArray['__OPERATION_BODY__'] = $arrOperationBody;
         $jsonstr = json_encode($sendArray);
         $FORMAT_XHEAD = "Ilogid/a16hiname/Iversion/Ireserved/Idetail_len";
         $binaryData = pack("Ia16III", $intLogID, "ccphp", 0, 0, strlen($jsonstr));
         $binaryData .= $jsonstr;
         //            var_dump(unpack($FORMAT_XHEAD, $binaryData));
         socket_set_option($this->m_sock, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" => 0));
         socket_set_option($this->m_sock, SOL_SOCKET, SO_SNDTIMEO, array("sec" => 1, "usec" => 0));
         socket_write($this->m_sock, $binaryData);
         $rstr = socket_read($this->m_sock, 32);
         if (32 != strlen($rstr)) {
             $len = strlen($rstr);
             Clogger::warning("socket_read error len: " . $len . " queuename: " . $strQueueName . " operation: " . $strOperation);
             return FALSE;
         }
         $retArray = unpack($FORMAT_XHEAD, $rstr);
         Clogger::notice("ciqueue queuename: " . $strQueueName . " operation: " . $strOperation . " response: " . json_encode($retArray));
         //            var_dump($retArray);
         return $retArray["reserved"] == 0;
     } else {
         Clogger::warning("connect error queuename: " . $strQueueName . " operation: " . $strOperation);
         return FALSE;
     }
 }
开发者ID:richardo2016,项目名称:flexse,代码行数:30,代码来源:ciqueueClient.Class.php

示例13: wake

 public function wake($mac, $ip)
 {
     global $l;
     //looking for values of wol config
     $wol_info = look_config_default_values('WOL_PORT');
     if (!isset($wol_info['name']['WOL_PORT'])) {
         $this->wol_send = $l->g(1321);
     } else {
         $wol_port = explode(',', $wol_info['tvalue']['WOL_PORT']);
     }
     foreach ($wol_port as $k => $v) {
         if (is_numeric($v)) {
             $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
             if (!$s) {
                 @socket_close($s);
                 $this->wol_send = $l->g(1322);
             } else {
                 $s_opt = socket_set_option($s, SOL_SOCKET, SO_BROADCAST, true);
                 socket_sendto($s, $this->pacquet($mac), strlen($this->pacquet($mac)), 0, "255.255.255.255", $v);
                 socket_close($s);
                 $this->wol_send = $l->g(1282);
             }
         }
     }
     //	$this->wol_send='toto';
     //return $wol_send;
 }
开发者ID:inkoss,项目名称:karoshi-server,代码行数:27,代码来源:function_wol.php

示例14: mServer

 public function mServer()
 {
     $sock = socket_create(AF_INET, SOCK_DGRAM, getprotobyname('udp'));
     $mIP = '239.255.255.250';
     if (!socket_bind($sock, $mIP, 1900)) {
         $errorcode = socket_last_error();
         $errormsg = socket_strerror($errorcode);
         die("Could not bind socket : [{$errorcode}] {$errormsg} \n");
     }
     socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array("group" => '239.255.255.250', "interface" => 0));
     while (1) {
         echo "Waiting for data ... \n";
         socket_recvfrom($sock, $buf, 512, 0, $remote_ip, $remote_port);
         echo "{$remote_ip} : {$remote_port} -- " . $buf;
         $query = $this->parseHeaders($buf);
         if (!isset($query["m-search"])) {
             continue;
         }
         $response = "HTTP/1.1 200 OK\r\n";
         $response .= "CACHE-CONTROL: max-age=1810\r\n";
         $response .= "DATE: " . date("r") . "\r\n";
         $response .= "EXT:\r\n";
         $response .= "LOCATION: http://192.168.7.123:9000/TMSDeviceDescription.xml\r\n";
         $response .= "SERVER: Linux/3.x, UPnP/1.1, fheME/0.6\r\n";
         $response .= "ST: urn:fheme.de:service:X_FIT_HomeAutomation:1\r\n";
         $response .= "USN: uuid:f6da16ab-0d1b-fe1c-abca-82aacf4afcac::urn:fheme.de:service:X_FIT_HomeAutomation:1\r\n";
         $response .= "Content-Length: 0\r\n";
         $response .= "\r\n";
         //Send back the data to the client
         socket_sendto($sock, $response, strlen($response), 0, $mIP, $remote_port);
     }
     socket_close($sock);
 }
开发者ID:nemiah,项目名称:fheME,代码行数:33,代码来源:phpUPnP.class.php

示例15: tcpStreamInitializer

 /**
  * Initializes a TCP stream resource.
  *
  * @param ParametersInterface $parameters Initialization parameters for the connection.
  *
  * @return resource
  */
 protected function tcpStreamInitializer(ParametersInterface $parameters)
 {
     $uri = "tcp://{$parameters->host}:{$parameters->port}";
     $flags = STREAM_CLIENT_CONNECT;
     if (isset($parameters->async_connect) && (bool) $parameters->async_connect) {
         $flags |= STREAM_CLIENT_ASYNC_CONNECT;
     }
     if (isset($parameters->persistent) && (bool) $parameters->persistent) {
         $flags |= STREAM_CLIENT_PERSISTENT;
         $uri .= strpos($path = $parameters->path, '/') === 0 ? $path : "/{$path}";
     }
     $resource = @stream_socket_client($uri, $errno, $errstr, (double) $parameters->timeout, $flags);
     if (!$resource) {
         $this->onConnectionError(trim($errstr), $errno);
     }
     if (isset($parameters->read_write_timeout)) {
         $rwtimeout = (double) $parameters->read_write_timeout;
         $rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1;
         $timeoutSeconds = floor($rwtimeout);
         $timeoutUSeconds = ($rwtimeout - $timeoutSeconds) * 1000000;
         stream_set_timeout($resource, $timeoutSeconds, $timeoutUSeconds);
     }
     if (isset($parameters->tcp_nodelay) && function_exists('socket_import_stream')) {
         $socket = socket_import_stream($resource);
         socket_set_option($socket, SOL_TCP, TCP_NODELAY, (int) $parameters->tcp_nodelay);
     }
     return $resource;
 }
开发者ID:medolyWu,项目名称:lvzhisha,代码行数:35,代码来源:StreamConnection.php


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