【问题标题】:Is it possible to write on an external socket using Guzzle?是否可以使用 Guzzle 在外部套接字上写入?
【发布时间】:2015-10-14 01:47:45
【问题描述】:

这是我的用例,我想转换这个 PHP 代码:

    $ctx = stream_context_create(array(
        'ssl' => array(
            'local_cert' => $myLocalCert,
            'passphrase' => $myPassphrase,
        ),
    ));
    $stream = stream_socket_client(
        'tls://gateway.sandbox.push.apple.com:2195',
        $errno,
        $errstr,
        30,
        STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,
        $ctx
    );

    fwrite($stream, $myMessage, strlen($myMessage));

使用伟大的Guzzle lib 进行类似的操作。

我知道 Guzzle 有一个 Stream 类,我们可以将其作为请求的“正文”发送,但我什至不知道 Guzzle 是否允许使用“http(s)”以外的其他协议...

这里有 Guzzle 专家吗? :)

【问题讨论】:

    标签: php sockets curl stream guzzle


    【解决方案1】:

    支持自定义协议似乎超出了 Guzzle 等 HTTP 客户端的范围。

    您是否正在向该端点发送 HTTP 消息?如果是这样,你为什么不能使用https?如果没有,您想使用 Guzzle 的哪些功能?大多数库都非常特定于 HTTP。

    【讨论】:

    • 不,这显然不是 HTTP 消息。好的,我只是认为 Guzzle Stream 对象会有所帮助。
    • 我认为您只需要一个通用的流包装器。您可以节省加载 Guzzle 的开销,只需编写 a small class 来处理您的协议
    猜你喜欢
    • 2012-01-25
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 2014-09-01
    相关资源
    最近更新 更多