Php 当使用类线程多线程、空格结果时,雄辩地保存数据库laravel
我在使用多线程php时遇到问题,我的代码如下 名称空间自动化\线程Php 当使用类线程多线程、空格结果时,雄辩地保存数据库laravel,php,multithreading,laravel,eloquent,pthreads,Php,Multithreading,Laravel,Eloquent,Pthreads,我在使用多线程php时遇到问题,我的代码如下 名称空间自动化\线程 use DB, Crypt, App; use Thread; use Automation\Models\UserLog; class myThread extends Thread { public function __construct($arg) { $this->arg = $arg; } public function run()
use DB, Crypt, App;
use Thread;
use Automation\Models\UserLog;
class myThread extends Thread {
public function __construct($arg) {
$this->arg = $arg;
}
public function run() {
if ($this->arg) {
$sleep = mt_rand(1, 10);
echo $this->arg." start : ".date("g:i:sa").Thread::getCurrentThreadId()."<br>";
sleep($sleep);
echo $this->arg." end : ".date("g:i:sa")."<br>";
//if added this code, this thread not gonna work
$userlog= new UserLog;
$userlog->user = "some user do something";
$userlog->save();
}
}
}
它出现在命令终端上的listen queue上,但不插入,我建议您使用
队列
,并在那里放置一些耗时的任务。多线程是一个复杂的解决方案,我不推荐使用。嗯,我不知道队列laravel是否可以大规模并行执行任务,我认为队列只是单/串行任务,需要先进先出(fifo)。上面的代码只是一个例子。我计划对海量数据/任务@GiedriusKiršys使用多线程
[PDOException]
could not find driver