我尝试使用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));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
有什么需要帮忙的吗?
谢谢
发布于 2017-06-02 01:38:00
试着改变这一点:
$client->addServer('127.0.0.1', '4730');
至
$client->addServer();
如果仍然不能工作,请尝试在php上查看此tutorial的get started页面。它对我来说很好用
发布于 2021-08-17 07:36:40
您忘记通过运行gearmand -d来启动gearman
在http://gearman.org/getting-started/的文档中了解更多关于它的信息
https://stackoverflow.com/questions/42460968
复制相似问题