0
我的線程腳本沒有看到線程中的另一個類。這是我的代碼。使用線程中的另一個類
require_once __DIR__.'\vendor\autoload.php';
use Symfony\Component\DomCrawler\Crawler;
$threadCount = 5;
$list = range(0,100);
$list = array_chunk($list, $threadCount);
foreach ($list as $line) {
$workers = [];
foreach (range(0,count($line)-1) as $i) {
$threadName = "Thread #".$i.": ";
$workers[$i] = new WorkerThreads($threadName,$line[$i]);
$workers[$i]->start();
}
foreach (range(0,count($line)-1) as $i) {
$workers[$i]->join();
}
}
class WorkerThreads extends Thread {
private $threadName;
private $num;
public function __construct($threadName,$num) {
$this->threadName = $threadName;
$this->num = $num;
}
public function run() {
if ($this->threadName && $this->num) {
$result = doThis($this->num);
printf('%sResult for number %s' . "\n", $this->threadName, $this->num);
}
}
}
function doThis($num){
$response = '<html><body><p class="message">Hello World!</p></body></html>';
$crawler = new Crawler($response);
$data = $crawler->filter('p')->text();
return $data;
}
當我運行它,我得到以下錯誤消息
Fatal error: Class 'Symfony\Component\SomeComponent\SomeClass' not found
我將如何讓我的線程看到另一個類?
您是否安裝了symfony中的組件工作的解決方案? – Federkun
@Federkun是的,我有。如果我在線程之外運行'doThis'函數,一切正常。 –