Jar*_*ier 1 php class function callback gearman
给定这一行代码来回调函数和回调函数本身:
Class MyClass {
public function doThings() {
$this->gearman->client->setCompleteCallback("workerCompleted");
}
public function workerCompleted() {
echo "worker is completed!";
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了 Message: GearmanClient::setCompleteCallback(): function workerCompleted is not callable
该setCompleteCallback方法需要引号中的函数名称,但如何调用类方法?$this->"workerCompleted"显然是错的.
$this->gearman->client->setCompleteCallback("workerCompleted");
Run Code Online (Sandbox Code Playgroud)
应该
$this->gearman->client->setCompleteCallback( array( $this, "workerCompleted"));
Run Code Online (Sandbox Code Playgroud)
因为您要指定对成员函数的回调,这需要一个需要调用的对象(或类名)的数组以及函数的名称.更多信息在文档.