Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to use DB class in Thread class?
  • I want to use task by multi thread. 
    I wrote following test code.
    But I got 'DB class not found'.

    fuel/app/tasks/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();
        }
    }

    fuel/app/classes/foo/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);
        }
    }

    Why DB class not found in thread?
    How to use?
  • Haven't got a clue what "Thread" is, but I assume it's something that executes outside the scope of the Framework...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion