【问题标题】:PHP gearman connection errorPHP gearman 连接错误
【发布时间】:2017-02-25 20:02:16
【问题描述】:

我尝试使用 gearman 在 PHP 中运行任务,我创建了 2 个脚本: 客户端.php

<?
$mail = array(
  'to' => 'test@gmail.com',
  'subject' => Hi',
  'body' => 'Test message',
);


# Connect to Gearman server
$client = new GearmanClient();
$client->addServer('127.0.0.1', '4730');


# Send message
$client->doBackground('sendmail', json_encode($mail));

worker.php

<?php
$worker = new GearmanWorker();
$worker->addServer();

$worker->addFunction('sendmail', 'send_mail');

while (1)
{
  $worker->work();
  if ($worker->returnCode() != GEARMAN_SUCCESS) break;
}

function send_mail($job)
{
  $workload = $job->workload();
  $data = json_decode($workload, true);

  mail($data['to'], $data['subject'], $data['body']);
}

当我从命令行运行我的工作人员时:php worker.php &

并运行我的 client.php 文件,我得到以下错误:

GearmanClient::doBackground(): send_packet(GEARMAN_COULD_NOT_CONNECT) 发送服务器选项包失败 -> libgearman/connection.cc:485

有什么帮助吗?

谢谢

【问题讨论】:

  • 我也会在工作端明确定义服务器。 $worker-&gt;addServer('127.0.0.1', '4730');.
  • 你的 gearman 服务器在运行吗?检查 'ps awux |grep gearmand'
  • 我在运行你的命令时得到这个:root 4515 0.0 0.0 103308 880 pts/0 S+ 05:49 0:00 grep gearmand

标签: php gearman


【解决方案1】:

尝试改变这一点:

$client-&gt;addServer('127.0.0.1', '4730');

$client-&gt;addServer();

如果仍然无法正常工作,请尝试在 php 上查看此 tutorialget started 页面。对我来说效果很好

【讨论】:

    【解决方案2】:

    你忘记通过运行 gearmand -d 来启动 gearman

    http://gearman.org/getting-started/的文档中了解更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-10
      • 2023-03-31
      • 2019-03-25
      • 2018-11-21
      • 2014-07-07
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      相关资源
      最近更新 更多