2015-10-28 71 views
1

我正在使用的項目我正在使用rabbitMQ來排列任務併發送消息。如果我從終端運行服務器和客戶端,我會收到數據,但是如果我嘗試將php包含在index.php中,並嘗試將其顯示到網頁中,則不起作用。我在做什麼錯了,我嘗試在函數中包裝testRabbitMQClient.php,但這仍然無效。我錯過了什麼?RabbitMQ:適用於終端,但不適用於PHP

<?php 
//index.php 

require 'openid.php'; 
require 'functions.php'; 
require 'testRabbitMQClient.php'; 
/* 
#connects to my database and checks to make sure its connected. 
*/ 
$apikey="key"; 
try { 
    $openid = new LightOpenID('localhost'); 
    if(!$openid->mode) { 
     if(isset($_GET['login'])) { 
      $openid->identity = 'http://steamcommunity.com/openid'; 
      header('Location: ' . $openid->authUrl()); 
     } 
?> 
<h1>Hey ____ thank you for using FOF.com</h1> 

<br> 
<?php 
    //showFriends(xxxxxxxxxxxxxxxxx); 
    //calls function from testRabbitMQClient.php  
    send("friends"); 

?> 
<form action="?login" method="post"> 
    <input type="image" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_border.png"> 
</form> 
<?php 
    } elseif($openid->mode == 'cancel') { 
     echo 'User has canceled authentication!'; 
    } else { 
     if($openid->validate()) { 
       $id = $openid->identity; 
       // identity is something like: http://steamcommunity.com/openid/id/76561197994761333 
       // we only care about the unique account ID at the end of the URL. 
       $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/"; 
       preg_match($ptn, $id, $matches); 
       echo "User is logged in (steamID: $matches[1])\n"; 
    } 
    else 
    { 
       echo "User is not logged in.\n"; 
     } 

    } 
} catch(ErrorException $e) { 
    echo $e->getMessage(); 
} 
?> 

#!/usr/bin/php 
<?php 
//rabbit mq client; 
require_once('path.inc'); 
require_once('get_host_info.inc'); 
require_once('rabbitMQLib.inc'); 

function send($type){ 
    $client = new rabbitMQClient("testRabbitMQ.ini","testServer"); 
    if (isset($argv[1])) 
    { 
     $msg = $argv[1]; 
    } 
    else 
    { 
     $msg = "test message"; 
    } 

    $request = array(); 
    $request['type'] = "friends"; 
    $request['username'] = "steve"; 
    $request['password'] = "password"; 
    $request['message'] = $msg; 
    $response = $client->send_request($request); 
    //$response = $client->publish($request); 

    echo "client received response: ".PHP_EOL; 
    echo $response; 
    echo "\n\n"; 

    echo $argv[0]." END".PHP_EOL; 
} 

?> 
+0

你有錯誤?沒有錯誤,但沒有排隊? –

+0

從瀏覽器運行此命令後,我得到了沒有錯誤,也沒有隊列。 – user2872194

+0

我不應該說不排隊,我應該說沒有排隊 – user2872194

回答

1

我想通了我的問題!我忘了在apache中啓用amqp。我通過將extension=amqp.so添加到位於apache文件夾中的php.ini文件來實現此目的。

相關問題