どのようにカスタムクラスを作成するのはコンポーネントクラスを拡張しないのですか?yii2でスレッドを拡張するカスタムクラスを作成
クラス:
namespace common\components;
class AsyncOperation extends Thread {
public function __construct($arg) {
$this->arg = $arg;
}
public function run() {
if ($this->arg) {
$sleep = mt_rand(1, 10);
printf('%s: %s -start -sleeps %d' . "<br />", date("g:i:sa"), $this->arg, $sleep);
sleep($sleep);
printf('%s: %s -finish' . "<br />", date("g:i:sa"), $this->arg);
}
}
}
yii2コントローラ:
public function actionTest() {
// Create a array
$stack = array();
//Iniciate Miltiple Thread
foreach (range("A", "D") as $i) {
$stack[] = new AsyncOperation($i);
}
// Start The Threads
foreach ($stack as $t) {
$t->start();
}
}
エラー:
PHP Fatal Error – yii\base\ErrorException
Class 'common\components\Thread' not found
This class is working perfect in pure php app
And Pthread is installed!
いいえ、それはちょうどテストですが、私はyii2の安らかなAPIのバックエンドでそれを使用しています! – mohsen
ああ私の神様、私は本当に嬉しいです、私は実際に泣くことができました... –
どういう意味ですか? – mohsen