RabbitMQ:适用于终端,但不适用于 PHP
RabbitMQ: Works in terminal, but not with PHP
对于我目前正在从事的项目,我正在使用 rabbitMQ 来排队任务和发送消息。如果我 运行 来自终端的服务器和客户端我将接收数据,但是如果我尝试将 php 包含在 index.php 中并试图将其显示到网页中不起作用。我做错了什么,我尝试将 testRabbitMQClient.php 包装在一个函数中,但这仍然没有 work.What 我错过了吗?
<?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;
}
?>
我解决了我的问题!我忘了在 apache 中启用 amqp。我通过将 extension=amqp.so
添加到位于 apache 文件夹中的 php.ini 文件来做到这一点。
对于我目前正在从事的项目,我正在使用 rabbitMQ 来排队任务和发送消息。如果我 运行 来自终端的服务器和客户端我将接收数据,但是如果我尝试将 php 包含在 index.php 中并试图将其显示到网页中不起作用。我做错了什么,我尝试将 testRabbitMQClient.php 包装在一个函数中,但这仍然没有 work.What 我错过了吗?
<?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;
}
?>
我解决了我的问题!我忘了在 apache 中启用 amqp。我通过将 extension=amqp.so
添加到位于 apache 文件夹中的 php.ini 文件来做到这一点。