[英]php pthreads won't launch on xampp 7.0.2
I have installed fresh xampp (7.0.2 atm). 我已经安装了新的xampp(7.0.2 atm)。 I've created php-cli.ini, added pthread extension there and set memory limit to 3 gb.
我创建了php-cli.ini,在其中添加了pthread扩展并将内存限制设置为3 GB。 But when I'am trying to launch thread script I got this:
但是,当我尝试启动线程脚本时,我得到了:
PHP Fatal error: Uncaught RuntimeException: cannot start my_thread, out of reso
urces in C:\xampp\htdocs\w\start_threads.php:160
Stack trace:
#0 C:\xampp\htdocs\w\start_threads.php(160): Thread->start()
#1 {main}
thrown in C:\xampp\htdocs\w\start_threads.php on line 160
Fatal error: Uncaught RuntimeException: cannot start my_thread, out of resources
in C:\xampp\htdocs\w\start_threads.php:160
(I'am using pthreds 3.1.5 x86) What am I doing wrong here? (我正在使用pthreds 3.1.5 x86)我在做什么错? Thank you!
谢谢!
Essentially, this is caused by pthread_create
returning EAGAIN
: It means that the system lacks resources to create another thread, or that the system imposed limit on the maximum number of threads (in a process, or system wide) has been reached. 本质上,这是由
pthread_create
返回EAGAIN
引起的:这意味着系统缺少创建另一个线程的资源,或者已达到系统(在一个进程或整个系统范围内)对最大线程数施加的限制。
This can be caused by two things, the purposeful use of more threads than a process can handle simultaneously as a result of the way some software is designed, or more perniciously, as a result of less than graceful joining of threads. 这可能是由两方面引起的:由于某些软件的设计方式,有目的地使用了比进程可以同时处理的线程更多的线程,或者由于线程的正常联接不足而更加有害。
If you only seem to hit such errors sometimes, it would suggest the latter is going on; 如果您有时似乎只遇到此类错误,则表明后者仍在继续。 Be sure to cleanup (explicitly join) threads you are done with to make behaviour predictable.
确保清理(明确加入)线程以使行为可预测。
My PHP version: 7.2.6 x82 And pthreads: php_pthreads-3.1.6-7.2-ts-vc15-x86 I created 25 threads, when created 21th thread then occurred same error. 我的PHP版本:7.2.6 x82和pthreads:php_pthreads-3.1.6-7.2-ts-vc15-x86我创建了25个线程,当创建第21个线程时发生了同样的错误。 I thought that it only can create 20 threads.
我以为它只能创建20个线程。 So I edited my code and that error does not occur My code:
所以我编辑了我的代码,但没有发生该错误我的代码:
class ReadAllFile extends Thread {
public $folder;
public function __construct($folder) {
$this->folder = $folder;
}
public function run() {
//code process
}
}
$dir = "F:/sbd/sbdstore/20180606/";
$subFolders = scandir ( $dir );
$stack = array();
foreach ( $subFolders as $folder ) {
if ($folder != '.' && $folder != '..') {
$stack[] = new ReadAllFile ( $dir.$folder );
}
}
$maxNumberOfThread = 20;
$numberOfRunning = 0;
$numberOfStack = count($stack);
$elementIsStarted = array();
$allElementIsProcess = false;
while(count($stack)){
if($numberOfRunning <= $maxNumberOfThread && !$allElementIsProcess){
for($i=0;$i<$numberOfStack;$i++){
if(!in_array($i,$elementIsStarted)){
$numberOfRunning++;
$elementIsStarted[] = $i;
$stack[$i]->start();
if($i == $numberOfStack - 1){
$allElementIsProcess = true;
}
$i = $numberOfStack + 1;
}
}
}else{
foreach($elementIsStarted AS $element){
if(isset($stack[$element]) && $stack[$element]->isRunning() !== true){
unset($stack[$element]);
$numberOfRunning--;
}
}
}
}
Hope this help. 希望对您有所帮助。 Sorry about my English.
对不起,我的英语。
P/s: If I use PHP version: 7.2.6 x64 and php_pthreads-3.1.6-7.2-ts-vc15-x64 then it does not occur this error. P / s:如果使用PHP版本:7.2.6 x64和php_pthreads-3.1.6-7.2-ts-vc15-x64,则不会发生此错误。 I think x64 allocation more memory.
我认为x64分配更多的内存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.