本文整理汇总了PHP中stream_socket_sendto函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_socket_sendto函数的具体用法?PHP stream_socket_sendto怎么用?PHP stream_socket_sendto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_socket_sendto函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
public function query($text)
{
$head = <<<_HEADER_
<?xml version="1.0" ?>
<wordsegmentation version="0.1">
<option showcategory="1" />
<authentication username="{$this->user}" password="{$this->passwd}" />
<text>
_HEADER_;
$footer = <<<_FOOT_
</text>
</wordsegmentation>
_FOOT_;
$this->data_send = $text;
$text = str_replace("&", " ", $text);
$querystr = $head . $text . $footer;
$tempxml = simplexml_load_string($querystr);
$resp = array();
if ($tempxml) {
if (stream_socket_sendto($this->sock, $tempxml->asXML())) {
do {
$ttt = stream_socket_recvfrom($this->sock, 65525);
$ttt = iconv('big5', 'utf-8', $ttt);
$resp[] = $ttt;
} while (!simplexml_load_string(implode($resp)));
return $this->data_recv = html_entity_decode(implode($resp));
}
} else {
$this->data_recv = 0;
return null;
}
}
示例2: processMessage
public function processMessage($message, $client)
{
$event = $message->event;
$data = $message->data;
$uuid = $message->uuid;
if ($event == "beforeEach") {
$data = $this->runner->runBeforeEachHooksForTransaction($data);
$data = $this->runner->runBeforeHooksForTransaction($data);
}
if ($event == "beforeEachValidation") {
$data = $this->runner->runBeforeEachValidationHooksForTransaction($data);
$data = $this->runner->runBeforeValidationHooksForTransaction($data);
}
if ($event == "afterEach") {
$data = $this->runner->runAfterHooksForTransaction($data);
$data = $this->runner->runAfterEachHooksForTransaction($data);
}
if ($event == "beforeAll") {
$data = $this->runner->runBeforeAllHooksForTransaction($data);
}
if ($event == "afterAll") {
$data = $this->runner->runAfterAllHooksForTransaction($data);
}
$messageToSend = ['uuid' => $uuid, 'data' => $data, 'event' => $event];
$messageToSend = json_encode($messageToSend);
stream_socket_sendto($client, $messageToSend . self::MESSAGE_END);
}
示例3: _send_udp
/**
* 发送UDP数据包
* @param $data
* @param $port
*/
static function _send_udp($data, $port)
{
if (self::$enable) {
$cli = stream_socket_client('udp://' . self::$sc_svr_ip . ':' . $port, $errno, $errstr);
stream_socket_sendto($cli, $data);
}
}
示例4: close_moniter
public function close_moniter()
{
$dmainid = trim($_POST['dmainid']);
//$dmain = trim($_POST['dmain']);
$dmain_list_db = new Dmain_list();
$val = $dmain_list_db->close_moniter($dmainid);
$list = [];
if (is_array($val) && count($val) > 0) {
foreach ($val as $value) {
$list[] = $value->dmain;
}
}
if (count($list) > 0) {
$list = implode('|', $list);
} else {
$list = '';
}
//写入redis共享给udp服务器
$redis = $this->getRedis();
$dmain_list = $redis->set('dmain', $list);
$socket = stream_socket_client('udp://211.151.98.92:9501');
$data = ['control' => 'reload'];
$data = json_encode($data) . '\\r\\n';
if (!$socket) {
exit(json_encode(false));
} else {
stream_socket_sendto($socket, $data);
exit(json_encode(true));
}
}
示例5: write
/**
* {@inheritdoc}
*/
public function write($string)
{
if (!$this->isWritable()) {
throw new RuntimeException("Stream is not writable");
}
return stream_socket_sendto($this->getContext(), $string);
}
示例6: write
/**
* {@inheritdoc}
*/
public function write($data = null)
{
if (isset($this->stream) === false) {
$this->createStream();
}
@stream_socket_sendto($this->stream, $data);
return true;
}
示例7: sendData
/**
* 发送数据给统计系统
* @param string $address
* @param string $buffer
* @return boolean
*/
public static function sendData($address, $buffer)
{
$socket = stream_socket_client($address);
if (!$socket) {
return false;
}
return stream_socket_sendto($socket, $buffer) == strlen($buffer);
}
示例8: write
/**
* Send the data
*
* @param $data
*
* @return mixed
*/
public function write($data = null)
{
$host = sprintf('udp://%s:%d', $this->config['host'], $this->config['port']);
// stream the data using UDP and suppress any errors
$stream = @stream_socket_client($host);
@stream_socket_sendto($stream, $data);
@fclose($stream);
return true;
}
示例9: sendData
/**
* 发送数据给统计系统
* @param string $address
* @param string $buffer
* @return boolean
*/
public static function sendData($address, $buffer, $timeout = 10)
{
$socket = stream_socket_client('tcp://' . $address, $errno, $errmsg, $timeout);
if (!$socket) {
return false;
}
stream_set_timeout($socket, $timeout);
return stream_socket_sendto($socket, $buffer) == strlen($buffer);
}
示例10: request
function request($request)
{
try {
$dt = call_user_func($this->callback, NULL, $request);
if (!empty($dt['data'])) {
stream_socket_sendto($this->srv, $dt['data'], 0, $this->cli);
}
} catch (Exception $e) {
cy_log(CYE_ERROR, "exception while processing.");
}
}
示例11: run
public function run()
{
$result = $this->_server->parse($this->_data);
if (empty($result['a'])) {
$data = $this->_data;
} else {
$this->_server = $this->route($this->_server);
$data = $this->_server->getData();
}
\stream_socket_sendto($this->_conn, $data . "\n");
}
示例12: send
/**
* Sends data on the connection.
*
* @param string $send_buffer
* @param bool $raw
* @return void|boolean
*/
public function send($send_buffer, $raw = false)
{
if (false === $raw && $this->protocol) {
$parser = $this->protocol;
$send_buffer = $parser::encode($send_buffer, $this);
if ($send_buffer === '') {
return null;
}
}
return strlen($send_buffer) === stream_socket_sendto($this->_socket, $send_buffer, 0, $this->_remoteAddress);
}
示例13: pingUdp
protected function pingUdp($target, $data)
{
if (!$this->monSocket) {
$this->monSocket = stream_socket_client($target, $errno, $errstr);
}
if ($this->monSocket) {
$post = http_build_query($data, '', '&');
stream_socket_sendto($this->monSocket, $post);
} else {
common_log(LOG_ERR, __METHOD__ . " UDP logging fail: {$errstr}");
}
}
示例14: add
public function add($response)
{
$contentLength = strlen($response);
$httpResponse = 'HTTP/1.0 200 OK
Date: ' . (new \DateTime())->format(\DateTIme::RFC822) . '
Server: PHP Robot Framework Remote Server
Connection: close
Content-Type: text/xml
Content-Length: ' . $contentLength . "\r\n" . "\r\n" . $response;
stream_socket_sendto($this->requestSocket, $httpResponse);
stream_socket_shutdown($this->requestSocket, STREAM_SHUT_RDWR);
}
示例15: writeSync
public function writeSync($data)
{
if ($this->writeEvent) {
$this->loop->removeWriteStream($this->connection);
$this->writeEvent = false;
}
$this->dataBuffer .= $this->buffer->encodeMessage(serialize($data));
while (strlen($this->dataBuffer) > 0) {
$this->ThrowOnConnectionInvalid();
$dataWritten = stream_socket_sendto($this->connection, $this->dataBuffer);
$this->dataBuffer = substr($this->dataBuffer, $dataWritten);
}
}