krakjoe / pthreads

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

PHP 5.6.24 x64 on Windows 2012 R2 crashes when accessing $this->worker from threaded #714

Closed sburning closed 7 years ago

sburning commented 7 years ago

I am using version 2.0.10 of pthreads for php 5.6 ts v11 x64, downloaded from http://windows.php.net/downloads/pecl/releases/pthreads/2.0.10/

I have also tried 2.0.09 with the same result.

I have tried the examples on two different servers with the same result(from event viewer): Faulting application name: php.exe, version: 5.6.24.0, time stamp: 0x57904dc0 Faulting module name: php_pthreads.dll, version: 5.6.0.0, time stamp: 0x542ba166 Exception code: 0xc0000005 Fault offset: 0x0000000000007f2c Faulting process id: 0x1c0c Faulting application start time: 0x01d2dec4df8946c3 Faulting application path: C:\php\php.exe Faulting module path: C:\php\ext\php_pthreads.dll

The CLI will always crash for me when accessing $this->worker. I have tried it from a threaded for a pool and by just extending a worker and a threaded without a pool, both result in the same issue. Here is one of the examples i tried. It crashes at the $this->worker->addData line. I have also tried just setting an id in the worker $this->id=int(1); and then accessing it in the threaded $this->worker->id and it crashes.

` class Searcher extends Worker { public $data = [];

public function run()
{
    echo 'Running '.$this->getStacked().' jobs'.PHP_EOL;
}

/**
 * To avoid corrupting the array
 * we use array_merge here instead of just
 * $this->data[] = $html
 */
public function addData($data)
{
    $this->data = array_merge($this->data, [$data]);
}

}

class SearchGoogle extends \Threaded { public function __construct($query) { $this->query = $query; }

public function run()
{
    echo microtime(true).PHP_EOL;
    //var_dump($this);
    $this->worker->addData(
        file_get_contents('http://google.fr?q='.$this->query)
    );
}

}

// Stack our jobs on our worker $worker = new Searcher(); $searches = ['dogs', 'cats', 'birds']; foreach ($searches as &$search) { $search = new SearchGoogle($search); $worker->stack($search); }

// Start all jobs $worker->start();

// Join all jobs and close worker $worker->shutdown(); foreach ($worker->data as $html) { echo substr($html, 0, 20).PHP_EOL; } `

Any ideas?

tpunt commented 7 years ago

I did try to replicate you issue (on OS X), but your example code seemed to work fine for me. So, unfortunately, I cannot offer any workarounds to your problem.

Also, pthreads v2 is no longer supported, and so no further updates will be made to it. So if there is a bug here, then it will not be fixed. If possible, upgrade to PHP 7 so that you can receive the latest bug fixes and features in pthreads v3.