PHP 套接字 fread 响应需要永远 [英] PHP socket fread response takes forever

查看:52
本文介绍了PHP 套接字 fread 响应需要永远的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 EPP 协议向注册商发送 XML 请求并获得响应,连接成功,但是当我到达 fread($fp) 时,它需要永远加载.

有没有办法让它快速并得到注册商的回复?

我在 hostbill 插件中使用下面的代码.

/** 打开套接字* */$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);如果 (!$fp) {$this->addError('Il y a une erreur dans la connexion:' . $errno . ' ' . $errstr);返回假;} 别的 {$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);

解决方案

你的 EPP 实现是错误的(当然如果服务器支持标准的话),见 RFC5734 我引用:

<块引用>

  1. 数据单元格式

    EPP 数据单元包含两个字段:一个 32 位的标头,用于描述数据单元的总长度,以及 EPP XML 实例.这EPP XML 实例的长度是通过减去四来自数据单元总长度的八位字节.接收者必须成功读取那么多八位字节以检索完整的 EPP XML处理 EPP 消息之前的实例.

还要注意第 3 部分,当您打开 TCP/TLS 连接时,首先发言的是带有 的服务器,因此作为客户端,您首先需要阅读该内容,然后发送您的登录信息.

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);

解决方案

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.

这篇关于PHP 套接字 fread 响应需要永远的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆