Selam arkadaşlar, pthreads'i ve Nginx'i ubuntu 16.10 makineme kurdum. Zts Enabled olarak değiştirdim. Örneklere bakarak düz .php dosyasında
//threadtest.php
<?php
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' . "\n", date("g:i:sa"), $this->arg, $sleep);
sleep($sleep);
printf('%s: %s -finish' . "\n", date("g:i:sa"), $this->arg);
}
}
}
// Create a array
$stack = array();
//Initiate Multiple Thread
foreach ( range("A", "D") as $i ) {
$stack[] = new AsyncOperation($i);
}
// Start The Threads
foreach ( $stack as $t ) {
$t->start();
}
?>
//run.php
<?php
system('php /var/www/test/threadtest.php');
?>
ve run.php çağırarak asenkron biçimde çalıştırabiliyorum. İş laravel'de yaptığım bir projeye gelince controller içerisinde şu şekilde çalıştırmayı deniyorum.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
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' . "\n", date("g:i:sa"), $this->arg, $sleep);
sleep($sleep);
printf('%s: %s -finish' . "\n", date("g:i:sa"), $this->arg);
}
}
}
class AdWordsController extends Controller
{
public function keywords()
{
$stack = array();
foreach ( range("A", "D") as $i ) {
$stack[] = new AsyncOperation($i);
}
foreach ( $stack as $t ) {
$t->start();
}
}
}
Class "Thread" Not Found hatası veriyor. Çözümü bir türlü bulamıyorum. Normal bir şekilde çalışan kod, laravel içerisinde neden çalışmıyor olabilir?
Çok teşekkür ederim.