tags:

views:

128

answers:

2

I am looking for PHP equivalent of the below code even if it is not a compilable code just providing the high level functions to use to perform each of these functionality would be great.


        string subscriptionUri = "sample.com";
        HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);
        sendNotificationRequest.Method = "POST";

        sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>");
        sendNotificationRequest.ContentType = "text/xml";


        sendNotificationRequest.ContentLength = notificationMessage.Length;
        byte[] notificationMessage = new byte[] {<payload>};

        using (Stream requestStream = sendNotificationRequest.GetRequestStream())
        {
           requestStream.Write(notificationMessage, 0, notificationMessage.Length);
        }

        // Sends the notification and gets the response.
        HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
        string notificationStatus = response.Headers["X-NotificationStatus"];
        string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
        string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];  

So basically I am looking for PHP equivalent of the following

  1. Send an Async request with some custom headers and content type and send it async/stream
  2. create a payload in byte from the string
  3. get the response and look at the headers.
A: 

The way to do it is using curl http://php.net/manual/en/book.curl.php with the settings:

  • CURLOPT_WRITEFUNCTION
  • CURLOPT_HEADERFUNCTION

I think that they allow async comm by using callback function. not 100% sure.

http://www.php.net/manual/en/function.curl-setopt.php

Nir
A: 
Bang Dao