2016-06-16 5 views
1

'Pusher php server'를 사용하여 Pusher를 PHP와 통합하려고합니다. xamp 서버를 사용하고 있습니다. 예제로 시도했지만 작동하지 않습니다. 아래 코드를 실행하면.Pusher가 PHP에서 작동하지 않습니다.

require('vendor\pusher\pusher-php-server\lib\Pusher.php'); 
$app_id = '216511'; 
$app_key = '40403e9b91d636322403'; 
$app_secret = '255060847263ef97c5d8'; 

class MyLogger { 
    public function log($msg) { 
    print_r($msg . "<br />"); 
    } 
} 

$pusher = new Pusher($app_key, $app_secret, $app_id); 
$logger = new MyLogger(); 
$pusher->set_logger($logger); 

$data['message'] = 'hello world'; 
$result = $pusher->trigger('test_channel', 'my_event', $data); 
$logger->log("---- My Result ---"); 
$logger->log($result); 

나는

Pusher: trigger POST: {"name":"my_event","data":"{\"message\":\"hello world\"}","channels":["test_channel"]} 
Pusher: exec_curl response: Array ([body] => Timestamp expired: Given timestamp (2016-06-17T06:26:35Z) not within 600s of server time (2016-06-16T06:26:55Z) [status] => 401) 

이 도와주세요 메시지를 받고 있습니다.

답변

-1

면책 조항 : 나는 그럼 난 정말 불행하게도 푸셔의 라이브러리를 도울 수 없어요,하지만 난 Ably, 우리는 실패가 보장하는 메커니즘의 번호를 가지고 말할 수 Ably - simply better realtime

의 공동 설립자이다 abrupt server failures 또는 network partitions or DNS failures과 같은 많은 경우를 처리했습니다.

다음 코드는 현재 시도하고있는 것을 달성하지만 Ably의 장애 조치 기능을 활용합니다.

require_once __DIR__ . '/../vendor/autoload.php'; 

// Don't embed your secrets in StackOverFlow! 
$appKey = '[OBTAIN-FREE-FROM-WWW.ABLY.IO-DASHBOARD]'; 
$opts = array(
    'key' => $appKey, 
    'logHandler' => function($level, $args) { 
    print_r($args[0] . "<br />"); 
    } 
); 
$client = new Ably\AblyRest($appKey); 
$channel = $client->channel('test_channel'); 

try { 
    $data['message'] = 'hello world'; 
    $channel.publish('my_event', $data); 
} catch (Exception $e) { 
    echo 'Publish failed: ', $e->getMessage(); 
}