我已经能够在亚马逊AWS服务器上成功安装gearman以及齿轮箱的PHP扩展。我按以下步骤运行我的设置:
但是,该过程不起作用。我认为这会被齿轮机客户困住。下面是我的客户端,服务器和工作人员的简单代码(以及日志文件输出和执行输出)
客户代码:
<?php
$client = new GearmanClient();
$client->addServer('localhost', 4730);
$arguments = array(
'url' => 'http://localhost/hit.php',
);
$client->addTask('fetchURL', json_encode($arguments));
print "running tasks";
if(!$client->runTasks())
{
echo "ERROR " . $client->error() . "\n";
exit;
}
else
print "task done";
echo "DONE";
工人代码:
<?php
$worker = new GearmanWorker();
$worker->addServer("localhost", 4730);
$worker->addFunction("fetchURL", "fetch_url");
print "Waiting for job...\n";
while($worker->work())
{
if ($worker->returnCode() != GEARMAN_SUCCESS)
{
echo "return_code: " . $worker->returnCode() . "\n";
break;
}
}
function fetch_url($job)
{
print "function called...\n";
$arguments = json_decode($job->workload(),TRUE);
if (!empty($arguments['url']))
{
print("Fetching " . $arguments['url'] . "\n");
return file_get_contents($arguments['url']);
}
}
服务器输出:
工人输出:
客户输出:
日志文件输出:
DEBUG 2016-09-02 12:06:38.848867 [ main ] THREADS: 4 -> libgearman-server/gearmand.cc:263
INFO 2016-09-02 12:06:38.848911 [ main ] Initializing Gear on port 4730 with SSL: false
INFO 2016-09-02 12:06:38.848956 [ main ] Starting up with pid 28079, verbose is set to DEBUG
DEBUG 2016-09-02 12:06:38.848997 [ main ] Method for libevent: epoll -> libgearman-server/gearmand.cc:362
DEBUG 2016-09-02 12:06:38.849036 [ main ] Trying to listen on 127.0.0.1:4730 -> libgearman-server/gearmand.cc:639
INFO 2016-09-02 12:06:38.849056 [ main ] Listening on 127.0.0.1:4730 (9)
DEBUG 2016-09-02 12:06:38.849064 [ main ] Creating wakeup pipe -> libgearman-server/gearmand.cc:903
DEBUG 2016-09-02 12:06:38.849069 [ main ] Creating 4 threads -> libgearman-server/gearmand.cc:376
DEBUG 2016-09-02 12:06:38.849076 [ main ] Initializing libevent for IO thread -> libgearman-server/gearmand_thread.cc:207
DEBUG 2016-09-02 12:06:38.849090 [ main ] Creating IO thread wakeup pipe -> libgearman-server/gearmand_thread.cc:478
DEBUG 2016-09-02 12:06:38.849119 [ main ] Thread 1 created -> libgearman-server/gearmand_thread.cc:256
DEBUG 2016-09-02 12:06:38.849149 [ main ] Initializing libevent for IO thread -> libgearman-server/gearmand_thread.cc:207
DEBUG 2016-09-02 12:06:38.849164 [ main ] Creating IO thread wakeup pipe -> libgearman-server/gearmand_thread.cc:478
DEBUG 2016-09-02 12:06:38.849183 [ main ] Thread 2 created -> libgearman-server/gearmand_thread.cc:256
DEBUG 2016-09-02 12:06:38.849189 [ main ] Initializing libevent for IO thread -> libgearman-server/gearmand_thread.cc:207
DEBUG 2016-09-02 12:06:38.849206 [ main ] Creating IO thread wakeup pipe -> libgearman-server/gearmand_thread.cc:478
DEBUG 2016-09-02 12:06:38.849225 [ main ] Thread 3 created -> libgearman-server/gearmand_thread.cc:256
DEBUG 2016-09-02 12:06:38.849230 [ main ] Initializing libevent for IO thread -> libgearman-server/gearmand_thread.cc:207
DEBUG 2016-09-02 12:06:38.849245 [ main ] Creating IO thread wakeup pipe -> libgearman-server/gearmand_thread.cc:478
DEBUG 2016-09-02 12:06:38.849268 [ main ] Thread 4 created -> libgearman-server/gearmand_thread.cc:256
DEBUG 2016-09-02 12:06:38.849273 [ main ] replaying queue: begin -> libgearman-server/gearmand.cc:389
DEBUG 2016-09-02 12:06:38.849276 [ main ] __replay -> libgearman-server/plugins/queue/default/queue.cc:101
DEBUG 2016-09-02 12:06:38.849279 [ main ] replaying queue: end -> libgearman-server/gearmand.cc:395
INFO 2016-09-02 12:06:38.849282 [ main ] Adding event for listening socket (9)
DEBUG 2016-09-02 12:06:38.849285 [ main ] Adding event for wakeup pipe -> libgearman-server/gearmand.cc:956
DEBUG 2016-09-02 12:06:38.849288 [ main ] Entering main event loop -> libgearman-server/gearmand.cc:404
DEBUG 2016-09-02 12:06:38.849336 [ 2 ] Entering thread event loop -> libgearman-server/gearmand_thread.cc:446
DEBUG 2016-09-02 12:06:38.849361 [ 3 ] Entering thread event loop -> libgearman-server/gearmand_thread.cc:446
DEBUG 2016-09-02 12:06:38.849379 [ 4 ] Entering thread event loop -> libgearman-server/gearmand_thread.cc:446
DEBUG 2016-09-02 12:06:38.849412 [ 1 ] Entering thread event loop -> libgearman-server/gearmand_thread.cc:446
DEBUG 2016-09-02 12:06:38.849422 [ main ] staring up Epoch thread -> libgearman-server/timer.cc:61
DEBUG 2016-09-02 12:06:38.855568 [ main ] accept() 32 -> libgearman-server/gearmand.cc:862
INFO 2016-09-02 12:06:38.855580 [ main ] Accepted connection from 127.0.0.1:33071
DEBUG 2016-09-02 12:06:38.855593 [ 4 ] Received CON wakeup event -> libgearman-server/gearmand_thread.cc:605
DEBUG 2016-09-02 12:06:38.855602 [ 4 ] setsockopt() fd:32 -> libgearman-server/io.cc:833
DEBUG 2016-09-02 12:06:38.855613 [ 4 ] 127.0.0.1:33071 Watching POLLIN -> libgearman-server/gearmand_thread.cc:151
DEBUG 2016-09-02 12:09:30.885913 [ main ] accept() 33 -> libgearman-server/gearmand.cc:862
INFO 2016-09-02 12:09:30.885943 [ main ] Accepted connection from 127.0.0.1:33073
DEBUG 2016-09-02 12:09:30.885969 [ 3 ] Received CON wakeup event -> libgearman-server/gearmand_thread.cc:605
DEBUG 2016-09-02 12:09:30.885983 [ 3 ] setsockopt() fd:33 -> libgearman-server/io.cc:833
DEBUG 2016-09-02 12:09:30.885993 [ 3 ] 127.0.0.1:33073 Watching POLLIN -> libgearman-server/gearmand_thread.cc:151
DEBUG 2016-09-02 12:09:34.144611 [ main ] accept() 34 -> libgearman-server/gearmand.cc:862
INFO 2016-09-02 12:09:34.144634 [ main ] Accepted connection from 127.0.0.1:33075
DEBUG 2016-09-02 12:09:34.144650 [ 2 ] Received CON wakeup event -> libgearman-server/gearmand_thread.cc:605
DEBUG 2016-09-02 12:09:34.144662 [ 2 ] setsockopt() fd:34 -> libgearman-server/io.cc:833
DEBUG 2016-09-02 12:09:34.144673 [ 2 ] 127.0.0.1:33075 Watching POLLIN -> libgearman-server/gearmand_thread.cc:151
我在日志中添加了行间距,以表示工作人员开始的位置。客户开始。从日志中看,客户端的行为也像工作者(或像客户端一样的工作者),因为工作者或客户端的日志事务之间似乎没有区别。我不确定日志事务是否应该更清晰,但这对我来说似乎很奇怪。
另外,我的齿轮手客户端没有退出。这很奇怪。
此后没有任何事情发生。我在某个地方出错了吗?这是我从阅读有关齿轮装备在线的多个教程的集体理解,但我仍然无法使其工作。任何帮助将不胜感激。
答案 0 :(得分:0)
我设法解决了这个问题。就像在client.php和worker.php
中将localhost更改为127.0.0.1一样简单不确定原因,但这有效。如果有人对此有解释,我很乐意知道:)