Send a subscription request

@param Request             $originRequest
@param SubscriptionMessage $message
@param OutputInterface     $output
@param boolean             $debug
321740
private function sendRequest(Request $originRequest, SubscriptionMessage $message, OutputInterface $output, bool $debug = false): void
    {
        $host = $originRequest->getHost();
        $port = $originRequest->getPort();
        $path = $originRequest->getPathInfo();

        $handle = fsockopen($originRequest->isSecure() ? 'ssl://'.$host : $host, $port, $errno, $errstr, 10);

        $signer = new Sha256();
        $subscriptionToken = (new Builder())->setId($message->getId())
                                            ->set('data', serialize($message->getData()))
                                            ->setIssuedAt(time())
                                            ->setNotBefore(time() + 60)
                                            ->setExpiration(time() + 60)
                                            ->sign($signer, $this->secret)
                                            ->getToken();

        $body = $originRequest->getContent();
        $length = strlen($body);
        $out = "POST $path HTTP/1.1\r\n";
        $out .= "Host: $host\r\n";
        $auth = $originRequest->headers->get('Authorization');
        $out .= "Authorization: $auth\r\n";
        $out .= "Subscription: $subscriptionToken\r\n";
        $out .= "Content-Length: $length\r\n";
        $out .= "Content-Type: application/json\r\n";
        $out .= "Connection: Close\r\n\r\n";
        $out .= $body;
        fwrite($handle, $out);

        if ($debug) {
            /// in debug mode wait for response
            $output->writeln(sprintf('[DEBUG] Getting response for subscription %s', $message->getId()));
            while (true) {
                $buffer = fgets($handle);
                if (!$buffer) {
                    break;
                }

                $output->write($buffer);
            }
        }
        fclose($handle);
    }
1047493
protected function _debug( $message, $args = null ) {
		$message = '[Factory] ' . $message;

		if ( func_num_args() == 1 ) {
			Debug::debug( $message );
		} else {
			$args = array_slice( func_get_args(), 1 );
			Debug::debugf( $message, $args );
		}
	}
579633
public static function message($message, $showHeader = true, HTTPRequest $request = null)
    {
        // Don't show on live
        if (Director::isLive()) {
            return;
        }

        echo static::create_debug_view($request)
            ->renderMessage($message, static::caller(), $showHeader);
    }
373127
public function sendMessage(Message $message)
    {
        $payload = $this->preparePayload($message);

        $encoded = json_encode($payload, JSON_UNESCAPED_UNICODE);

        if ($encoded === false) {
            throw new RuntimeException(sprintf('JSON encoding error %s: %s', json_last_error(), json_last_error_msg()));
        }

        $this->guzzle->post($this->endpoint, ['body' => $encoded]);
    }
794087
public function sendMessage($recipient, $message, $notificationType = NotificationType::REGULAR, $messagingType = MessagingType::RESPONSE)
    {
        $message = $this->createMessage($message);
        $options = RequestOptionsFactory::createForMessage($recipient, $message, $notificationType, $messagingType);
        $response = $this->client->send('POST', '/me/messages', null, [], [], $options);
        $responseData = $this->decodeResponse($response);

        return new MessageResponse($responseData['recipient_id'], $responseData['message_id']);
    }
1021080
public function send($output, OutputStrategyInterface $outputStrategy = null)
    {
        if (!($outputStrategy instanceof OutputStrategyInterface)) {
            $outputStrategy = $this->defaultOutputStrategy;
        }

        $contentType = new Header(
            Header::CONTENT_TYPE,
            $outputStrategy->getMime()
        );

        $this->header($contentType);

        return $outputStrategy->send($output);
    }
1058790
public static function debug($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
    {
        self::log(LogLevel::DEBUG, $message, $context, $channel);
    }
482150
public function write($data, $debug = true)
    {
        if (fwrite($this->_stream, $data . "\r\n") === false) {
            throw new Horde_Imap_Client_Exception(
                Horde_Imap_Client_Translation::r("Server write error."),
                Horde_Imap_Client_Exception::SERVER_WRITEERROR
            );
        }

        if ($debug) {
            $this->_params['debug']->client($data);
        }
    }
852160
public function sendMessage(MessageInterface $message, array $recipients)
    {
        $messageProcessor = new MessageProcessor($this->getProcessorStore());
        $message = $messageProcessor->preProcessMessage($message);

        foreach ($recipients as $recipient) {
            foreach ($this->getChannels($message, $recipient) as $channel) {
                $processedMessage = $messageProcessor
                    ->processMessage(clone($message), $recipient);
                if ($channel->isHandling($processedMessage, $recipient)) {
                    $channel->send($processedMessage, $recipient);
                }
            }
        }
    }
267823
public function send(OutgoingMessage $message)
    {
        $messageToSend = $message->serialize();
        $length = strlen($messageToSend);
        $this->logger->debug(
            '------ Sending: ------ ' . "\n" . $messageToSend . '----------'
        );
        $this->lastActionId = $message->getActionId();
        if (@fwrite($this->socket, $messageToSend) < $length) {
            throw new ClientException('Could not send message');
        }
        $read = 0;
        while ($read <= $this->rTimeout) {
            $this->process();
            $response = $this->getRelated($message);
            if ($response != false) {
                $this->lastActionId = false;
                return $response;
            }
            usleep(1000); // 1ms delay
            if ($this->rTimeout > 0) {
                $read++;
            }
        }
        throw new ClientException('Read timeout');
    }
230321
public static function reply(InteropMessage $replyMessage, $status = self::ACK, $reason = null)
    {
        $status = null === $status ? self::ACK : $status;

        $result = new static($status, $reason);
        $result->setReply($replyMessage);

        return $result;
    }
428313
public function debug(string $message, array $context = []){
        if($this->logger !== null){
            $this->logger->debug($message, $context);
        }

        if($this->messagePanel !== null){
            $this->messagePanel->addMessage($message, LogLevel::DEBUG);
        }
    }
1070631
@Override
  public void sendRegistrationTerminationRequest(JRegistrationTerminationRequest request)
      throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    send(Event.Type.SEND_MESSAGE, request, null);
  }
141384
public function onWorkerMessage(MessageInterface $msg)
    {
        if ($msg instanceof Protocol\ActionListRequest) {
            $this->getLogger()->debug('[SERVICE] Returning list of actions.');
            $this->stream->send(new Protocol\ActionListResponse($this->getActionList()));

            return;
        }

        if ($msg instanceof Protocol\ExecuteJobRequest) {
            $requestId = $msg->getRequestId();
            $action = $msg->getAction();

            $this->getLogger()->debug('[SERVICE] Job for action: '.$action.' with id: '.$requestId);

            $params = array();
            $serialized = $msg->getParams();
            foreach ($serialized as $param) {
                $params[] = $this->getSerializer()->unserialize($param);
            }

            if (!isset($this->actions[$action])) {
                $this->getLogger()->notice('[SERVICE] Action '.$action.' not found.');
                $this->stream->send(new Protocol\ActionNotFound($requestId, $action));

                return;
            }

            $return = $this->execute($action, $params);
            $sendReturn = $this->getSerializer()->serialize($return);

            $this->stream->send(new Protocol\ExecuteJobResponse($requestId, $sendReturn));

            return;
        }

        throw new RuntimeException('Invalid request.');
    }
1138516
public function debug($message, array $context = [])
    {
        if ($this->logger instanceof LoggerInterface) {
            $this->logger->debug($message, $context);
        }
    }
65458
protected function debug($message)
    {
        if ($this->debug) {
            if ($this->debug_handler) {
                call_user_func_array(
                    $this->debug_handler, array(&$this, $message)
                );
            } else {
                echo "DEBUG: $message\n";
            }
        }
    }
1172956
protected function listenForConsoleCommands(InputInterface $input, OutputInterface $output, $message)
    {
        if ($message === '/quit') {
            $output->writeln('Exiting...');
            die();
        }

        if ($message === '/reload') {
            return $this->execute($input, $output);
        }

        if ($message === '/help') {
            $output->writeln('');
            $output->writeln('<comment>Usage:</comment>');
            $output->writeln('  Type a message and press Return to send.');
            $output->writeln('');
            $output->writeln('<comment>Commands:</comment>');
            $output->writeln('  <info>/help</info>        Show this text');
            $output->writeln('  <info>/reload</info>      Reload the interactive console');
            $output->writeln('  <info>/quit</info>        Quit the interative console');
            $output->writeln('');

            $this->waitForUserInput($input, $output);
        }

        return null;
    }