pthreads(一)爆线程堆栈

1 脚本

<?php
class demo extends Thread{ // 需pthreads扩展
    public $num = 0;
    public function __construct($num){
        $this->num = $num;
    }

    public function run(){
        echo "$this->num run\n";
        return $this->num;
    }
}

$pool=[];
for($i = 0 ;$i < 10000000 ; $i++){
    $pool[$i] = new demo($i);
    echo "memory: ".memory_get_usage()."\n";
    $pool[$i]->start();
}



2 运行(命令行下)

~
memory: 3294800
8995 run
memory: 3295016
memory: 3295232
8996 run
Killed
[~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3295232 / 1024
3218

3218 / 1024
3 // 线程堆栈 3M ?


3 PHP的core

-rw-------  1 root       root       123908096 Nov 24 18:51 core.19209

[~]# php -c core.19209
PHP:  syntax error, unexpected '(' in /home/who/core.19209 on line 1 //  爆堆栈导致的BUG

你可能感兴趣的:(PHP,线程,堆栈,pthreads)