Writes to the socket

@param resource $socket Socket
@param string $message Message
432048
protected function writeToSocket($socket, $message)
    {
        socket_sendto($socket, $message, strlen($message), 0, PAPERTRAIL_HOST, PAPERTRAIL_PORT);
    }
652584
public function publish($channel, $message)
    {
        $topic = $this->getTopicForChannel($channel);
        $payload = Utils::serializeMessage($message);

        if ($this->backgroundBatching) {
            $topic->batchPublisher()->publish(['data' => $payload]);
        } else {
            $topic->publish(['data' => $payload]);
        }
    }
687671
protected function write($message, array $record = array())
    {
        $record = array_merge($this->defautlRecord, $record);
        $record['msg'] = $message;
        $this->output->writeln($this->formatter->format($record));
    }
630722
public function write($message)
    {
        if (null !== $this->_file_handler) {
            if (fwrite($this->_file_handler, $message) === false) {
                throw new Exception('The file could not be written', 500, Exception::FILESYSTEM);
            } else {
                $this->_last_line = trim($message);
                ++$this->_line_count;

                if ($this->_flush_frequency && $this->_line_count % $this->_flush_frequency === 0) {
                    fflush($this->_file_handler);
                }
            }
        }
    }
91180
public function send(Message $message) : void
    {
        header('Content-Type: text/xml', true);

        $xml = $this->getOutputToSend($message);
        if ($xml !== false) {
            Utils::getContainer()->debugMessage($xml, 'out');
            echo $xml;
        }

        // DOMDocument::saveXML() returned false. Something is seriously wrong here. Not much we can do.
        exit(0);
    }
696737
public function write($buffer)
    {
        $buffer = (string) $buffer;
        $bufLen = Binary::safeStrlen($buffer);

        $socket = $this->getSocket();
        $written = 0;

        while ($written < $bufLen) {
            // PHP's fwrite does not behave nice in regards to errors, so we wrap
            // it with a temporary error handler and treat every warning/notice as
            // a error
            $failed = false;
            $errorMessage = "Failed to write to socket";
            set_error_handler(function ($errno, $errstr) use (&$failed, &$errorMessage) {
                $failed = true;
                $errorMessage .= ": $errstr ($errno)";
            });
            $byteCount = fwrite($socket, Binary::safeSubstr($buffer, $written));
            restore_error_handler();

            if ($byteCount === 0 && defined('HHVM_VERSION')) {
                $failed = true;
            }

            if ($failed || $byteCount === false) {
                throw new \RuntimeException($errorMessage);
            }

            $written += $byteCount;
        }


        return $written;
    }
1237194
protected function onClientMessage(string $message, int $socketId): Generator
    {
        yield Dispatcher::async($this->broadcast(Frame::encode($message)));
    }
1128628
private function composition($receiver, stdClass $message)
    {
        if(!$this->broadcast)
        {
            $this->typing($receiver);
            
            sleep($this->manager->composition($message));

            $this->paused($receiver);
        }
    }
907139
protected function loop($socket)
    {
        while (true) {
            try {
                $result = $this->read($socket);  // is blocking
            } catch (\RuntimeException $e) {
                break;
            }
            $this->write($socket, call_user_func($this->procedure, $result));
        }
    }
261264
protected function _writeStream($buffer) {
        $fd = $this->socket_;
        $total = TStringFuncFactory::create()->strlen($buffer);

        // Early out on the trivial case
        if ($total <= 0) {
            return;
        }

        $failed = FALSE;
        $sent = 0;

        while (!$failed && $sent < $total) {

            if (!is_resource($fd)) {
                $failed = TRUE;
            }

            try {
                // Supress any error messages as it is considered part of normal
                // operation for the write to fail on a broken pipe or timeout
                $written = @fwrite($fd, $buffer, self::MAX_BYTES_PER_WRITE);

                if ($written > 0){
                    $sent += $written;
                    $buffer = substr($buffer, $written);

                } else if ($written === FALSE) {
                    if ($this->debug_) {
                        error_log("Write failed.");
                    }
                    $failed = TRUE;

                } else if ($written === 0) {
                    if ($this->debug_) {
                        error_log("Zero bytes written to socket. sent=$sent total=$total");
                    }
                    $failed = TRUE;
                } else {
                    if ($this->debug_) {
                        error_log("Unexpected fwrite return value '$written'");
                    }
                    $failed = TRUE;
                }

                if ($this->debug_) {
                    error_log("Written = $written bytes. Sent $sent of $total.");
                }

            } catch (Exception $e) {
                if ($this->debug_) {
                    error_log($e);
                }
                $failed = TRUE;
            }
        }

        if ($failed) {
            $this->_closeSocket();
        }
    }
636475
protected function writeln(OutputInterface $output = null, $message)
    {
        if ($output instanceof OutputInterface) {
            $output->writeln($message);
        }
    }
1134464
private function stdout($type, $message)
        {
            if (!defined('STDOUT') || !$this->debug) {
                return false;
            }

            $typeMap = array(
                'debug'   => array(36, '- debug -'),
                'info'    => array(37, '- info  -'),
                'error'   => array(31, '- error -'),
                'ok'      => array(32, '- ok    -'),
            );

            if (!Arrays::exists($type, $typeMap)) {
                throw new Exception('Socketio::stdout $type parameter must be debug, info, error or success. Got '.$type);
            }

            fwrite(STDOUT, "\033[".$typeMap[$type][0]."m".$typeMap[$type][1]."\033[37m  ".$message."\r\n");
        }
1234016
protected function log($message)
    {
        if ($this->log_handle == null) {
            $this->log_handle = fopen($this->config['logfile'], 'a');
        }
        fwrite($this->log_handle, $message);
    }
707208
public function write(string $level, string $message, array $context)
    {
        $levnum = Logger::getLevelNumeric($level);
        if ($levnum < $this->min_level)
            return;

        $lvl = sprintf("%10s", $level);
        $message = $this->format($lvl, $message, $context);
        $this->log[] = $message; //sprintf("%10s: %s", strtoupper($level), $message);
    }
939519
function writeToLog($message) {
		if ($this->logFile) {
			$timestamp = date("Y-m-d H:i:s");
			$timestamp = str_pad($timestamp, 20);
			if (isset($_SERVER["REMOTE_ADDR"])) {
				$ip = $_SERVER["REMOTE_ADDR"];
			} else {
				$ip = "Unknown IP";
			}
			$ip = str_pad($ip, 15);
			$taggedMessage = "$timestamp $ip $message\n";
			file_put_contents($this->logFile, $taggedMessage, FILE_APPEND);
		}
		if ($this->logCallback) {
			call_user_func_array($this->logCallback, array($message));
		}
	}
1121313
public void send(byte[] message) {
		try {
			ps.write(message);
		} catch (IOException ioe) {
			System.out.println(new LogEntry(Level.CRITICAL, "IO exception occurred while writing to client", ioe));
			connection.close("IO exception occurred while writing to client");
		}
	}
1185522
protected function writeln($message, $verbosity = OutputInterface::VERBOSITY_NORMAL, $type = OutputInterface::OUTPUT_NORMAL)
    {
        if ($this->verbosity >= $verbosity) {
            $this->output->writeln($message, $type);
        }
    }