加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 通过http代理的stream_socket_client

发布时间:2020-12-13 17:42:12 所属栏目:PHP教程 来源:网络整理
导读:我正在研究APNS(Apple推送通知服务). 我正在按照教程说的那样做: $ctx = stream_context_create();stream_context_set_option($ctx,'ssl','local_cert','ck.pem');stream_context_set_option($ctx,'passphrase',$passphrase);$fp = stream_socket_client( '
我正在研究APNS(Apple推送通知服务).
我正在按照教程说的那样做:

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

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

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

解决方法

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

$ctx = stream_context_create(array(
        'http' => array(
            'proxy' => 'tcp://127.0.0.1:8888',)
        )
       );

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读