7

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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I just wanna point out that proxy is not a supported param by stream_socket_client() and is completely ignored. php.net/manual/en/context.socket.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.