I've created a simple class:
class Event {
var $a;
var $b;
var $c;
function __construct($a, $b, $c)
{
$this->a= $a;
$this->b = $b;
$this->c= $c;
}
}
Then I've created another class which extends Thread:
class WorkerThread extends Thread
{
private $myUrl;
private $eventsArr;
private $counterDebug;
private $postdata;
public function __construct($myUrl, $postdata)
{
$this->myUrl = $myUrl;
$this->postdata = $postdata;
$this->eventsArr = array();
$this->counterDebug=0;
}
public function run()
{
$flag=false;
foreach ($json as $key => $value) {
$this->counterDebug++;
/* Death event */
$event= new Event($a, $b, $c);
array_push($this->eventsArr, $event);
}
}
}
}
echo (count($this->eventsArr));
echo (json_encode($event));
echo ("\n" . $this->counterDebug);
if($flag && count($this->events)>0){
...
When trying to add new created objects into the array, it stays empty.
What I've figured from debugging:
1) The objects are created.
2) neither eventsArr[]= $event, nor array_push are working.
3) I've set a counter that verifies the objects are being created and should be added to the array.
What am I doing wrong?
p.s-
I've removed irrelevant parts of code in order to simplify things.
pthreads? They work fine but not needed that often? As an 'experiment' also good. Except you didn't allow any other pthreads to run? pthreads have to give some result thenwaituntil they get control back?