我想通过多线程使用任务。 我编写了以下测试批处理(任务)代码。
燃料/应用程序/任务/ test.php的
<?php
namespace Fuel\Tasks;
class Test
{
public static function run()
{
// worked
\Foo_Bar::insert(10);
$bar = new \Foo_Bar();
// worked
$bar->run();
// not worked!!(Error: Class 'DB' not found)
$bar->start();
$bar->join();
}
}
燃料/应用/类/富/ bar.php
<?php
class Foo_Bar extends Thread
{
public static function insert($i)
{
DB::insert('test')->set(array(
'i' => $i,
))->execute();
}
public function run()
{
$this->insert(20);
}
}
仅在线程中,找不到DB类。 为什么不工作? 请帮我。 谢谢。
答案 0 :(得分:0)
如果您的错误是DB Class无法在您的线程上运行,我尝试了您的代码。请添加&#39; \&#39;在班级名称之前。实施例
eecode year w2011 w2012 w2013
1 2012 7 8 9
1 2013 7 8 9
2 2011 20 25 25
2 2012 20 25 25
2 2013 20 25 25