本文整理汇总了PHP中socket_write函数的典型用法代码示例。如果您正苦于以下问题:PHP socket_write函数的具体用法?PHP socket_write怎么用?PHP socket_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了socket_write函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: sock_write
function sock_write(&$sock, $data, $length = 0, $flush = false)
{
$sock->error = "";
$sock->errno = 0;
if (empty($length)) {
$length = strlen($data);
}
$ret = false;
$retries = 5;
while (($ret === false || $ret < $length) && $retries > 0) {
$ret += @socket_write($sock->socket, substr($data, $ret), $length - $ret);
if ($ret === false || $ret < $length) {
usleep(500);
}
$retries--;
}
if ($ret === false || $ret < $length) {
$sock->errno = 0;
if ($ret < $length && $ret !== false) {
$sock->error = "Socket write timeout";
} else {
$sock->error = "Socket write error";
}
}
/* else if ($flush)
sock_flush($sock);*/
}
开发者ID:romaninsh,项目名称:cps-api,代码行数:27,代码来源:lib_sock.inc.php
示例4: send
public function send($data)
{
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket == null) {
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $this->timeout, 'usec' => 0));
if (!socket_connect($socket, $this->host, $this->port)) {
return false;
}
$packed = json_encode($data);
echo $packed;
//Write Header
socket_write($socket, "ZBXD");
//Write Data length
$length = strlen($packed);
socket_write($socket, pack("V*", $length, $length >> 32));
socket_write($socket, $packed);
$return_header = socket_read($socket, 5);
$return_length = unpack("V*", socket_read($socket, 8));
$return_length = $return_length[1] + ($return_length[2] << 32);
$return_data = socket_read($socket, $return_length);
$return_data = json_decode($return_data);
socket_close($socket);
return $return_data;
}
开发者ID:OneOaaS,项目名称:zabbix-dashboard-extension,代码行数:26,代码来源:Zabbix.php
示例5: run_loop
function run_loop()
{
//This will stall the thread / request
$i = 0;
while ($_SESSION['running'] != -1) {
#read from local socket and put on session variable
while ($out = socket_read($this->socket, 8192)) {
if ($out === false) {
exit("[Server] Unable to read from local socket");
}
$this->met_data .= $out;
}
#If data on SESSION variable write data to local socket
if ($this->handler_data != "") {
$in = socket_write($this->socket, $this->handler_data, strlen($this->handler_data));
if ($in === false) {
exit("[Server] Unable to write to local socket");
}
$this->handler_data = "";
}
$this->update_session_data();
if (!stristr(PHP_OS, "linux")) {
sleep(1);
}
//added to work with apache/IIS on windows otherwise the consecutive reads DoS the socket
}
}
开发者ID:ROIXppttdr,项目名称:hack_tools_for_me,代码行数:27,代码来源:conn.php
示例6: hg_sendCmd
function hg_sendCmd($cmd, $ip, $port)
{
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
return false;
}
$result = socket_connect($socket, $ip, $port);
if ($result < 0) {
return false;
}
if (!isset($cmd['charset'])) {
$cmd['charset'] = '';
}
$str = json_encode($cmd);
//echo ($str);
//$str = base64_encode($str);
socket_write($socket, $str, strlen($str));
$data = '';
while ($out = socket_read($socket, 256)) {
$data .= $out;
if (strlen($out) < 256) {
break;
}
}
socket_close($socket);
//$data = base64_decode($data);
return $data;
}
开发者ID:h3len,项目名称:Project,代码行数:28,代码来源:functions.php
示例7: ircReport
function ircReport($stuff)
{
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($sock, Settings::pluginGet("host"), Settings::pluginGet("port"));
socket_write($sock, $stuff . "\n");
socket_close($sock);
}
开发者ID:RoadrunnerWMC,项目名称:ABXD-plugins,代码行数:7,代码来源:init.php
示例8: listenForClients
function listenForClients()
{
$this->serviceConnection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($this->serviceConnection, $this->serviceHost, $this->servicePort);
socket_listen($this->serviceConnection, 10);
echo 'LISTENING ',$this->servicePort,"\n";
while($clientSocket = socket_accept($this->serviceConnection))
{
socket_write($clientSocket, "OK\n");
$deviceToken = trim(socket_read($clientSocket, 512, PHP_NORMAL_READ));
$message = trim(socket_read($clientSocket, 512, PHP_NORMAL_READ));
if(!empty($deviceToken) && !empty($message))
{
$this->sendNotification($deviceToken, $message);
socket_write($clientSocket, "SENT\n");
}
else
{
socket_write($clientSocket, "ERROR\n");
}
socket_close($clientSocket);
}
}
开发者ID:nard,项目名称:Pushchat-Server,代码行数:28,代码来源:PushService.php
示例9: run
public function run()
{
$ret = array();
while (true) {
$inArr = $this->get_files_by_ext($this->urlFilePath, 'url');
if (!empty($inArr)) {
sleep(2);
foreach ($inArr as $in) {
if (!in_array($in, $ret)) {
$ret[] = $in;
exec("cp {$this->urlFilePath}{$in} {$this->backupFilePath}");
$fileContent = file_get_contents($this->urlFilePath . $in);
if (socket_write($this->socket, $fileContent, strlen($fileContent))) {
$this->addLog("发送到服务器信息成功!发送的内容为: {$fileContent}");
sleep(2);
} else {
$this->addLog("发送失败! reason :" . socket_strerror($this->socket));
}
}
}
} else {
$this->addLog("无URL文件");
sleep(1);
}
}
}
开发者ID:alice-jiao,项目名称:Practice,代码行数:26,代码来源:client.php
示例10: 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
示例11: sendAll
/**
* send summary to graphite
* @return bool - status of operation (TRUE = success, FALSE = failure)
*/
public function sendAll()
{
$bucket_prefix = $this->buildBucketPrefix();
$address = gethostbyname($this->cfg['host']);
$cmdBuf = '';
foreach ($this->stats_summary as $stat) {
// action name mapping
$action = preg_replace('/[\\. ]/', '', $stat['action']);
$action = preg_replace('/_ACTION$/', '', $action);
// HACK to prevent old event names to appear in graphite
if (!preg_match('/_/', $action)) {
continue;
}
$cmdBuf .= $bucket_prefix . $action . ' ' . $stat['value'] . ' ' . $stat['time'] . "\n";
}
// var_dump($cmdBuf);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, $address, $this->cfg['port']);
if (!$result) {
return false;
}
$write_result = socket_write($socket, $cmdBuf, strlen($cmdBuf));
if (!$write_result) {
return false;
}
return true;
}
开发者ID:rukzuk,项目名称:rukzuk,代码行数:31,代码来源:GraphiteStats.php
示例12: query
function query($query_string, $timeout)
{
$tmp = "";
$string = "";
$stime = array();
$this->timer($stime);
$n = strlen($query_string);
if ($this->is_connected == 0) {
$this->reconnect();
}
if ($this->sock && $n > 0 && socket_write($this->sock, $query_string, $n) == $n) {
while (1) {
if ($tmp = socket_read($this->sock, 81920, PHP_BINARY_READ)) {
if (($n = strpos($tmp, SOCK_END)) === FALSE) {
$string .= $tmp;
} else {
$string .= substr($tmp, 0, $n + strlen(SOCK_END));
break;
}
} else {
$this->close();
return false;
}
$usec = $this->timer($stime);
if ($usec >= $timeout) {
$this->close();
return false;
}
usleep(1);
}
return $string;
}
$this->close();
return false;
}
开发者ID:houweifeng,项目名称:sbase,代码行数:35,代码来源:cinterface.inc.php
示例13: write
/**
* Write data to socket
*
* @param $data
*
* @throws Exception\IO\ReadException
*/
function write($data)
{
if (!socket_write($this->socketResource, $data, strlen($data))) {
throw new WriteException($this, $data);
}
$this->getEventDispatcher()->dispatch(WriteEvent::getEventName(), new WriteEvent($this, $data));
}
开发者ID:beeyev,项目名称:Socket,代码行数:14,代码来源:Socket.php
示例14: await
private function await()
{
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($sock < 0) {
echo "Error:" . socket_strerror(socket_last_error()) . "\n";
}
$ret = socket_bind($sock, $this->ip, $this->port);
if (!$ret) {
echo "BIND FAILED:" . socket_strerror(socket_last_error()) . "\n";
exit;
}
echo "OK\n";
$ret = socket_listen($sock);
if ($ret < 0) {
echo "LISTEN FAILED:" . socket_strerror(socket_last_error()) . "\n";
}
do {
$new_sock = null;
try {
$new_sock = socket_accept($sock);
} catch (Exception $e) {
echo $e->getMessage();
echo "ACCEPT FAILED:" . socket_strerror(socket_last_error()) . "\n";
}
try {
$request_string = socket_read($new_sock, 1024);
$response = $this->output($request_string);
socket_write($new_sock, $response);
socket_close($new_sock);
} catch (Exception $e) {
echo $e->getMessage();
echo "READ FAILED:" . socket_strerror(socket_last_error()) . "\n";
}
} while (TRUE);
}
开发者ID:jasper2007111,项目名称:notes,代码行数:35,代码来源:server.php
示例15: refresh_user
function refresh_user($discord_id)
{
global $socket, $error;
$so = socket_create(AF_UNIX, SOCK_DGRAM, 0);
if ($so === false) {
$msg = socket_strerror(socket_last_error());
$error = "Socket failed: {$msg}";
} else {
$res = socket_connect($so, $socket);
if ($res === false) {
$msg = socket_strerror(socket_last_error());
$error = "Connect failed: {$msg}";
} else {
$payload = json_encode(array('action' => 'refresh', 'user_id' => $discord_id));
$res = socket_write($so, $payload);
if ($res === false) {
$error = "Socket send failed";
} else {
if ($res < strlen($payload)) {
$error = "Socket did not send all data";
}
}
socket_shutdown($so);
socket_close($so);
}
}
}
开发者ID:Hornwitser,项目名称:DiscordAuthorizer,代码行数:27,代码来源:forumbot.html.php
示例16: send
/**
* Send message package to the socket server
* Basic layer method
*
* @return mixed
*/
public function send($msg, $is_block = false)
{
if (!$this->host || !$this->port) {
throw new Hush_Socket_Exception("Please set server's host and port first");
}
/* Create a TCP/IP socket. */
$this->sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->sock < 0) {
echo "socket_create() failed.\nReason: " . socket_strerror($this->sock) . "\n";
}
$result = @socket_connect($this->sock, $this->host, $this->port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ({$result}) " . socket_strerror($result) . "\n";
}
if ($is_block) {
@socket_set_nonblock($this->sock);
}
// add suffix for socket msg
$msg = trim($msg) . "\r\n";
@socket_write($this->sock, $msg, strlen($msg));
$result = @socket_read($this->sock, 2048);
// unserialize data from socket server
$result = unserialize(trim($result));
return $result;
}
开发者ID:LWFeng,项目名称:hush,代码行数:31,代码来源:Client.php
示例17: write
public function write($body)
{
$this->updateStatus();
if ($this->writable) {
socket_write($this->_socket, $body, strlen($body));
}
}
开发者ID:ZyManch,项目名称:lumza,代码行数:7,代码来源:Http.php
示例18: perform_handshaking
function perform_handshaking($receved_header, $client_conn, $host, $port)
{
//se crea un arreglo para guardar los datos enviados del cliente
$headers = array();
//divide el contenido enviado por el cliente en array,por medio de la expresion regular
//crea los array apartir el retorno de carro (\r) y salto de linea (\n).
$lines = preg_split("/\r\n/", $receved_header);
//recorre el arreglo LINES para meterlo en el arreglo HEADERS
foreach ($lines as $line) {
$line = chop($line);
//elimina los espacios en blanco
//Aqui se crea un arreglo matches donde se anexara al arreglo HEADERS donde el indicide de
//headers tendra el valor de maches[1] y su valor sera el de matches[2]
if (preg_match('/\\A(\\S+): (.*)\\z/', $line, $matches)) {
$headers[$matches[1]] = $matches[2];
}
}
$secKey = $headers['Sec-WebSocket-Key'];
// se obtiene el balor de Sec-WebSocket-Key
//genera el encriptado base64 para responder al cliente
//sha1 calcula el has del string
//pack empaqueta el sha1 a una cadena binaria donde H* indica que debe ser todo el texto
//en cadena hexadecimal.
//base64_encode codifica el paquete binario en base64
$secAccept = base64_encode(pack('H*', sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
//hand shaking header -- Crea el mensaje para el cliente y se extablesca la conexion
$upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . "Upgrade: websocket\r\n" . "Connection: Upgrade\r\n" . "WebSocket-Origin: {$host}\r\n" . "WebSocket-Location: ws://{$host}:{$port}/servidor.php\r\n" . "Sec-WebSocket-Accept:{$secAccept}\r\n\r\n";
//envia al cliente la respuesta para establecer la comunicacion entre cliente y socket
socket_write($client_conn, $upgrade, strlen($upgrade));
}
开发者ID:alexmac10,项目名称:websockets,代码行数:30,代码来源:servidor.php
示例19: sendUSD
function sendUSD($text, $pass_server = '000000')
{
$address = gethostbyname('127.0.0.1');
//IP Адрес вашего компьютера
$service_port = 8000;
//Порт
//$pass_server='000000'; //Пароль
$phone = preg_replace('/^\\+/', '', $phone);
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
echo "socket create failed reason: " . socket_strerror($socket) . "\n";
}
$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
echo "socket connect failed.\nReason: ({$result}) " . socket_strerror($result) . "\n";
}
$text = iconv("UTF-8", "Windows-1251", $text);
$in = base64_encode($pass_server . "#CMD#[USSD]" . $text);
//Пример отправки смс
//$in = base64_encode($pass_server."#CMD#[USSD]*102#"); //Пример запроса USSD команды
$out = '';
socket_write($socket, $in, strlen($in));
//echo "Response:\n\n";
$res = '';
while ($out = socket_read($socket, 2048)) {
$res .= $out;
}
socket_close($socket);
$res = iconv("Windows-1251", "UTF-8", $res);
if (preg_match('/USSD-RESPONSE\\[.+?\\]:(.+)/is', $res, $m)) {
$res = $m[1];
}
return $res;
}
开发者ID:cdkisa,项目名称:majordomo,代码行数:34,代码来源:smsgw.php
示例20: BroadCastMessage
public function BroadCastMessage($Message)
{
$str = json_encode($Message) . "#";
foreach ($this->clients as $client) {
socket_write($client, $str, strlen($str));
}
}
开发者ID:Waqee,项目名称:Raft-php,代码行数:7,代码来源:Sender.php
注:本文中的socket_write函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论