Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stream_socket_client via http proxy

Tags:

php

ssl

sockets

I'm working on APNS (Apple Push Notification Service). I'm doing it as tutorials said:

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

But on my server, I have to connect to the internet via a HTTP proxy, so I always got timeout error with those code. How can I set http proxy for strem_socket_client with ssl protocol?

like image 515
Allen Hsu Avatar asked Jul 23 '12 06:07

Allen Hsu


1 Answers

Best way is to set proxy options with stream_context_create:

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

See http://php.net/manual/en/context.http.php for full http options. Maybe you will have to set request_fulluri to true.

like image 190
Matej Avatar answered Sep 21 '22 18:09

Matej