$this->res = fopen("php://stdout", "w"); /* * tell the waiting process we have created symbols and fetch will succeed */ $t = $this; $this->synchronized(function () use($t) { $t->notify(); }); /* wait for the process to be finished with the stream */ $this->synchronized(function () use($t) { $t->wait(); }); } } $thread = new Fetching(); $thread->start(); $thread->synchronized(function ($me) { $me->wait(); }, $thread); /* * we just got notified that there are symbols waiting */ foreach (array("sym", "arr", "obj", "objs", "res") as $symbol) { printf("\$thread->%s: ", $symbol); $fetched = $thread->{$symbol}; if ($fetched) { switch ($symbol) { /* * manual unserialize */ case "objs":
* resources never supported */ $this->res = fopen("php://stdout", "w"); /* * tell the waiting process we have created symbols and fetch will succeed */ $this->notify(); sleep(2); /* * wait for waiting process to fetch symbols */ $this->wait(); } } $thread = new Fetching(); $thread->start(true); /* * we just got notified that there are symbols waiting */ foreach (array("sym", "arr", "obj", "objs", "res") as $symbol) { printf("Thread::fetch(%s): ", $symbol); $fetched = $thread->{$symbol}; if ($fetched) { switch ($symbol) { /* * we need to manually serialize objects here */ case "objs": print_r(unserialize($fetched)); break; default: