stream_socket_client通过http代理

All*_*Hsu 5 php sockets ssl

我正在研究APNS(Apple推送通知服务).我正在按照教程说的那样做:

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

$fp = stream_socket_client(
    'ssl://gateway.sandbox.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
Run Code Online (Sandbox Code Playgroud)

但是在我的服务器上,我必须通过HTTP代理连接到互联网,所以我总是得到这些代码的超时错误.如何使用ssl协议为strem_socket_client设置http代理?

Mat*_*tej 8

最好的方法是设置proxy选项stream_context_create:

$ctx = stream_context_create(array(
        'http' => array(
            'proxy' => 'tcp://127.0.0.1:8888',
            )
        )
       );
Run Code Online (Sandbox Code Playgroud)

有关完整的http选项,请参见http://php.net/manual/en/context.http.php.也许你必须设置request_fulluri为true.

  • 我只是想指出代理不是 stream_socket_client() 支持的参数,并且完全被忽略。http://php.net/manual/en/context.socket.php (5认同)