我在Beanstalkd设置中做错了。我已经创建了一个生产器,但是它像无限循环一样不断加载。 I also posted this issue to GitHub。
我尝试添加2个带有简单数组的试管,但是遇到的另一个问题是,当我使用试管的名称时,它没有我期望的值:它总是获得旧的值管。
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require("vendor/autoload.php");
function p($s){
echo "<pre>";
print_r($s);
echo "</pre>";
}
use Pheanstalk\Pheanstalk;
$pheanstalk = new Pheanstalk('127.0.0.1'); //initiating an object
$watches = $pheanstalk->watch("ashimatube103613");
if ($pheanstalk->getConnection()->isServiceListening() == true) {
p($job = $pheanstalk->reserve());
while($job = $pheanstalk->reserve()) {
$getdata = $job->getData();
p($getdata);
echo 'test this is ';
$pheanstalk->delete($job);
}
}
$start = $pheanstalk->getConnection()->isServiceListening(); // true or false
echo $start."listening";
try {
# $job = $pheanstalk->reserve();
# p($job->getData());
echo 'here test';
} catch (Exception $e) {
echo "Error sending message - {$e->getMessage()} \n";
}
我做错了什么?
这是我的生产者代码:producer.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
#echo phpinfo();
require("vendor/autoload.php");
function p($s){
echo "<pre>";
print_r($s);
echo "</pre>";
}
use Pheanstalk\Pheanstalk;
$pheanstalk = new Pheanstalk('127.0.0.1'); //initiating an object
$args = array(
"date" => "2017-1-17",
"id"=>array("7","8","39","4")
);
#producer
$put = $pheanstalk->useTube("ashimatube103613")->put(json_encode(array($args)));
exit();
您可能想要无限循环。用于工作者/侦听器的许多示例代码都有无限循环,这可能是实现目标的最简单方法。它不应该通过网络服务器运行,因此不受Apache或Nginx的超时限制的约束:此代码可以永远有效地运行。它可能*应该。它需要不断监视队列,以便它始终知道何时可以处理新任务。