krakjoe / pthreads

Threading for PHP - Share Nothing, Do Everything :)
Other
3.47k stars 503 forks source link

windows server 2012 and Stackable (pools and workers) #332

Closed bimbiman closed 9 years ago

bimbiman commented 10 years ago

there is no $this->worker in work object on windows server 2012

bimbiman commented 10 years ago

ive tested it on 5.5,5.6 86 and 64bit.

and it seems that worker object in work like a black hole - when try to execute worker fucntion ($this->worker->foo()), or just var_dump($this->worker) or even var_dump($this) (where worker object is), script just OUTPUT NOTHING. Real buggy on windows 2012 server. so for keep working, i had to transfer all functions from worker to work and use worker just like class Bla_bla extends Worker{} for declareting Pool for example

bimbiman commented 10 years ago

Seems its STACKABLE problem.

class StackableArray extends Stackable { public function run() {} } class T extends Thread { public function __construct($test){ $this->test = $test; $this->start(); } public function run(){ $this->test[]=rand(1,2); -------------------- FAILLLLL return true; } $test=new StackableArray(); foreach($qs as $q){ $ts[]=new T($test); }

AND IF public function __construct($test){ $this->test = $test; var_dump($this->test); - we could see it. but if thread start - we lost it. //$this->start(); }

krakjoe commented 10 years ago

Sorry about the delay.

Please provide reproducing code for the bug.

I'll get to it as quick as I can, again sorry about the delay.

bimbiman commented 10 years ago

No problem. Anyway thx for php multithreading. And we all also know that ur busy. So, just try ur examples Pooling.php StackableArray.php SQLWorker.php

on windows server 2012. and u will see. any 32\64bit php 5.3-5.6 ts.

cmygeHm commented 10 years ago

We have this bug too. If you pass not StackableArray instanse to thread you can access to it in "run" method. Otherwise it fails.

bimbiman commented 10 years ago

i dont know about 7 (if u mean server version), becouse in win7 64bit pro - all ok.

also i detect that on windows sometimes in highload scripts with 100-200 threads after finish CLI process dont quit. i dont know why. max_exec time not working. seems its Windows buggy. But its not fatal, becouse you can kill process by "timeout".

but StackableArray in win server - really problem =(

cmygeHm commented 10 years ago

Excuse me... We tried it on Windows 8 64, php 32 bit Windows 7 64, php 32 bit. It works fine! It seems trouble in php. Trouble on Win8 64 with php 64 bit.

<?php

function println($text)
{
    echo $text . PHP_EOL;
}

class ATest extends Stackable
{
    private $a;

    public function __construct($a = 0)
    {
        $this->a = $a;
    }

    public function hello()
    {
        println(sprintf("Hello World #%d", $this->a++));
    }
}

class Test extends Thread
{
    private $test;

    public function __construct(ATest $test)
    {
        $this->test = $test;
    }

    public function run()
    {
        $this->test->hello();
    }
}

$test = new ATest;
$thread = new Test($test);
$thread->start();
$thread->join();

$test->hello();
krakjoe commented 10 years ago

Please can someone confirm if this is still present ?

bimbiman commented 10 years ago

i will test it today again.

krakjoe commented 10 years ago

Thanks :)

krakjoe commented 10 years ago

poke @bimbiman :)

bimbiman commented 10 years ago

1 moment ;] testing 5.5 and 5.6 with latest version

bimbiman commented 10 years ago

in win8\windows server 2012 64bit + 64bit php doesnt work pooling.php from examples and next test script:

<?php

class MegaTask extends Stackable {  

    public function __construct($i){
        $this->i = $i;
    }

    public function run(){
        $this->worker->foo1($this->i);
        $this->complete = true;
    }
    public function isComplete() {
        return $this->complete;
    }

    protected $complete;
}

class WebWorker extends Worker {

    public function foo1($a){
        echo $a;
    }
}

$pool = new Pool(10, \WebWorker::class);

for($i=0; $i < 10; $i++){
    $pool->submit(new MegaTask($i));
}

$pool->shutdown();
$pool->collect(function($work){
    return $work->isComplete();
});

?>

->worker->foo1 - isnt work. $this->worker Like black hole

krakjoe commented 10 years ago

Is this with 2.0.9 ?

bimbiman commented 10 years ago

http://windows.php.net/downloads/pecl/releases/pthreads/ 2.0.8 max =)

krakjoe commented 10 years ago

Sorry, windows releases are built when pecl releases are done and 2.0.9 is master today, will do a release today or tomorrow.

bimbiman commented 10 years ago

i will test it today\tomorrow

krakjoe commented 9 years ago

Closing, if this still exists in PHP7, open a new issue ;)