phpsocketstcpprovisioningepp

PHP socket fread response takes forever


I want to send XML requests via EPP protocole to a registrar and get responses, the connection is successful, but when I get to fread($fp) , it takes forever to load.

Is there a way to make it fast and get a response from the registrar?

I am using the code bellow in a hostbill plugin.

 /** open socket* */
        $fp = fsockopen("tcp://registrarwebsite.com", 700, $errno, $errstr, 200);

        stream_set_blocking($fp, true);

        stream_context_set_option($fp, 'ssl', 'verify_host', true);
        stream_context_set_option($fp, 'ssl', 'verify_peer', true);
        stream_context_set_option($fp, 'ssl', 'allow_self_signed', false);
        stream_context_set_option($fp, 'ssl', 'local_cert', __DIR__ . '/ma_cert.pem');
        stream_context_set_option($fp, 'ssl', 'local_pk', __DIR__ . '/ma_key.pem');


        // $secure = stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
        // stream_set_blocking($fp, false);

        if (!$fp) {
            $this->addError('Il y a une erreur dans la connexion: ' . $errno . ' ' . $errstr);
            return false;
        } else {

            $xml = htmlentities($this->prepareXMLRequest($xml));

            fwrite($fp, $xml);

            $out = fread($fp, 1024);

            fclose($fp);

            $out1 = htmlentities($fp);

            $this->addError('<span style="color: green !important">Connexion se fait avec succes, le code retourné est : </span> ' . $out1);

Solution

  • Your EPP implementation is wrong (if the server supports the standard up to the letter of course), see RFC5734 which I quote:

    1. Data Unit Format

    The EPP data unit contains two fields: a 32-bit header that describes the total length of the data unit, and the EPP XML instance. The length of the EPP XML instance is determined by subtracting four octets from the total length of the data unit. A receiver must successfully read that many octets to retrieve the complete EPP XML instance before processing the EPP message.

    Note also section 3 that shows when you open the TCP/TLS connection the first party to speak is the server with the <greeting> so as the client you first need to read that and then send your login.