我试图使用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']);
}
当我从Comand Line运行工人时:php worker.php&amp;
运行我的client.php文件,我会收到以下错误:
gearmanclient :: dobackground():send_packet(gearman_could_not_connect)无法发送服务器-Options数据包 -> libgearman/connection.cc:485
请有任何帮助吗?
谢谢
尝试更改以下内容:
$client->addServer('127.0.0.1', '4730');
to
$client->addServer();
如果仍然没有工作,请尝试在本教程的PHP的"入门"页面中查看。它对我来说很好
您忘了通过运行gearmand -d
在http://gearman.org/getting-started/