T
T
tigra2017-12-04 18:05:25
PHP
tigra, 2017-12-04 18:05:25

Why does calling class methods in a thread not see other classes?

I wanted to run 2 functions in a thread, connected pthreads, followed the example
. I created 2 handler classes (workers), I call them, add them to the pool and call them.

$pool = new Pool(2, 'Worker');
        $pool->submit(new Thread($worker1));
        $pool->submit(new Thread($worker2));

        while ($pool->collect(function ($work) {
            return $work->isGarbage();
        })) continue;

        $pool->shutdown();

but I get the error Error: Class 'common\models\GoodsCategoryRelations' not found in WorkerClass, if you just call WorkerClass, then everything works, but inside the \Threaded class it doesn’t see, maybe someone came across that it doesn’t see other classes inside the thread

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tigra, 2018-03-19
@tigroid3

as it turned out, for security reasons, inside, when starting a thread in the pool, starting from some version, you can’t pass anything inside by type: function ($t) use ($class)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question