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);
    }
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);
    }
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 ) ; }
Send a subscription request

@param Request             $originRequest
@param SubscriptionMessage $message
@param OutputInterface     $output
@param boolean             $debug
Send a subscription request