要仔細(xì)看手冊(cè)啊,我把手冊(cè)的內(nèi)容給你COPY到這兒:
6、定時(shí)函數(shù)為類的方法
use \Workerman\Worker;
use \Workerman\Lib\Timer;
require_once __DIR__ . '/Workerman/Autoloader.php';
class Mail
{
// 注意,回調(diào)函數(shù)屬性必須是public
public function send($to, $content)
{
echo "send mail ...\n";
}
}
$task = new Worker();
$task->onWorkerStart = function($task)
{
// 10秒后發(fā)送一次郵件
$mail = new Mail();
$to = 'workerman@workerman.net';
$content = 'hello workerman';
Timer::add(10, array($mail, 'send'), array($to, $content), false);
};
// 運(yùn)行worker
Worker::runAll();