PHP gearman连接错误

PHP gearman连接错误,php,gearman,Php,Gearman,我试图使用gearman在PHP中运行任务,我创建了两个脚本: 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', '4

我试图使用gearman在PHP中运行任务,我创建了两个脚本: 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));
尝试更改此选项:

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

$client->addServer()


如果仍然无法工作,请尝试查看php上的页面。它对我来说很好

我也会在工作端明确定义服务器<代码>$worker->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
$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']);
}