2009-11-10 129 views
3

我寫了下面的腳本來閱讀反饋數據。但是,由於某些原因,我沒有收到來自服務器的任何數據。你能否讓我知道腳本有什麼問題。另外,如果你有任何工作的PHP腳本的反饋服務,你可以分享它...推送通知的反饋服務

問候, DD。

<?php 

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


// Set time limit to indefinite execution 
set_time_limit (0); 

// Set the ip and port we will listen on 
$address = 'ssl://feedback.sandbox.push.apple.com'; 
$port = 2196; 

// Create a TCP Stream socket 
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 
echo "PHP Socket Server started at " . $address . " " . $port . "\n"; 

// Bind the socket to an address/port 
socket_bind($sock, $address, $port) or die('Could not bind to address'); 
// Start listening for connections 
socket_listen($sock); 

//loop and listen 

while (true) { 
    /* Accept incoming requests and handle them as child processes */ 
    $client = socket_accept($sock); 

    // Read the input from the client – 1024 bytes 
    $input = socket_read($client, 1024); 


} 

// Close the client (child) socket 
socket_close($client); 

// Close the master sockets 
socket_close($sock); 

?> 

回答

1

您必須充當客戶端,就像您要發送通知一樣。那一定是這樣的:

<?php 
$certFile = 'apns-dev.pem'; 

while (true) { 
    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', $certFile); 
    //stream_context_set_option($ctx, 'ssl', 'passphrase', $this->certPass); 
    echo "try to open stream\n"; 
    $fp = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $err, $errstr, 5, STREAM_CLIENT_CONNECT, $ctx); 
    if (!$fp) { 
     print "Failed to connect". $err . $errstr. "\n"; 
     exit(); 
    } else { 
     echo 'Connected to feedback sandbox...'; 
     while (($in = fread($fp, 1024)) != EOF) { 
      echo 'read '. $in . "\n"; 
     } 

     socket_close($fp); 
     fclose($fp); 
    } 
    sleep(2000); 
} 
?> 
相關問題