运行 异步 while 函数或多线程
Run asynchronous while functions or multithread
我有一个使请求同步的功能。
但是,我需要循环让这个函数同时执行多次。
PHP 7.2 中最好的方法是什么?
我的代码没有按预期工作:
class AsyncOperation extends Thread
{
public function __construct($threadId)
{
$this->threadId = $threadId;
}
public function run()
{
runMyFunction();
}
}
$start = microtime(true);
for ($i = 1; $i <= 100; $i++) {
$t[$i] = new AsyncOperation($i);
$t[$i]->start();
}
你可以阅读它(A succinct parallel concurrency API for PHP 7)-> https://github.com/krakjoe/parallel
我有一个使请求同步的功能。 但是,我需要循环让这个函数同时执行多次。 PHP 7.2 中最好的方法是什么?
我的代码没有按预期工作:
class AsyncOperation extends Thread
{
public function __construct($threadId)
{
$this->threadId = $threadId;
}
public function run()
{
runMyFunction();
}
}
$start = microtime(true);
for ($i = 1; $i <= 100; $i++) {
$t[$i] = new AsyncOperation($i);
$t[$i]->start();
}
你可以阅读它(A succinct parallel concurrency API for PHP 7)-> https://github.com/krakjoe/parallel