Bellow是我用来验证电子邮件地址存在的脚本,使用pthreads来提高速度。 问题是,当我把它放入Laravel命令时,我得到了这个错误:
Fatal error: Call to undefined method Illuminate\Support\Facades\Log::error() in /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 208
这是剧本:
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class verifyLocal extends Command
{
protected $name = 'verify:local';
protected $description = 'verify emails from local server';
public function __construct()
{
parent::__construct();
}
public function fire()
{
$start = microtime(true);
$emails = array(
new WebRequest("email_1@gmail.com"),
new WebRequest("email_2@gmail.com")
);
$threads = array();
foreach ($emails as $k => $email) {
$req[$k] = new WebRequest($email);
$threads[$k] = new WebWorker();
$threads[$k]->start();
$threads[$k]->stack($req[$k]);
}
/* wait for completion */
foreach ($threads as $thread) {
$thread->shutdown();
}
foreach ($req as $r) {
var_dump($r);
}
$time = microtime(true) - $start;
printf("Fetched %d responses in %.3f seconds\n", count($req), $time);
}
}
class WebRequest extends Stackable {
public $email_address;
public $response_body;
public function __construct($email_address) {
$this->email_address = $email_address;
}
public function run(){
$this->response_body = $this->check($this->email_address);
}
public function check($email) {
/* verification code here */
$answer = true;
return $answer;
}
}
class WebWorker extends Worker {
public function __construct () {
}
public function run(){
}
}
?>
请帮忙。感谢。
答案 0 :(得分:2)
我不使用Laravel,我的猜测是你需要在Worker / Thread的run方法中安装自动加载器,这样laravel才能正常工作,先试试......
foreach ($emails as $k => $email) {
$req[$k] = new WebRequest($email);
$threads[$k] = new WebWorker();
$threads[$k]->start();
$threads[$k]->stack($req[$k]);
}
这表示你想为每封电子邮件创建一个工作人员,这确实非常浪费。