PHP gearman连接错误

时间:2017-02-25 20:02:17

标签: php gearman

我尝试使用gearman在PHP中运行任务我创建了2个脚本: client.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&amp;

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

GearmanClient :: doBackground():send_packet(GEARMAN_COULD_NOT_CONNECT)无法发送服务器选项数据包 - &gt; libgearman / connection.cc:485

请帮忙吗?

由于

1 个答案:

答案 0 :(得分:0)

尝试改变这一点:

$client->addServer('127.0.0.1', '4730');

$client->addServer();

如果仍无法正常工作,请尝试查看php上此get startedtutorial页面。它对我来说很好用