Environment CentOS 6.3 64bit,php 5.4.5 pthreads need thread security environment download PHP installation package, unzip: Tar zxvf php-5.4.5.tar.gz//name is not I'm not sure about this. Download Install: /configure--enable-zts--prefix=/usr/local/php-zts make make install As a result, the thread-mounted version of PHP was installed to/usr/local/php-zts, and I don't know what the impact of open thread safety is, so get two beta versions. Download and install Pthreads: tar zxvf pthreads CD pthreads-0.0.45//This is the first stable version /usr/local/php-zts/bin/ Phpize./configure--with-php-config=/usr/local/php-zts/bin/php-config make make install /usr/ Local/php-zts/bin/php-igrep "PHP.ini" to find the php.ini position, modify it to put ext= Pthreads.so joined in, because I originally have PHP, now the new php.ini file does not exist I have a test in the past ... there are some sample files in the Pthreads-0.0.45/examples directory that are more useful than documents. The online documentation does not explain the problem at all, I modified one and executed it:
<?php/* Sharing symbols * @NOTE Thread::fetch is never included in a-release and is superceeded by obj ECT handlers * Pthreads allows read access to thread data from the any context pthreads allows write access to thread
Data from the any context carry on reading ... work in progress ... */class Testobject {public $val;
Class fetching extends Thread {public Function run () {/* * of course ... * *
$this->sym = 10245;
$this->arr = Array ("1", "2", "3");
Echo ' 6 '. chr (10);
* * objects do work, no preparation needed ... * read/write objects-isn ' t finalized.
* So did the dance to make it work ... * * * $obj = new Testobject ();
$obj->val = "TestVal";
$this->obj = $obj;
Echo ' 7 '. chr (10); /* would always work * * * $this->OBJS = Serialize ($this->obj);
Echo ' 8 '. chr (10);
* * * nooooooo/$this->res = fopen ("Php://stdout", "w");
Echo ' 9 '. chr (10); /* Tell the waiting process we have created symbols and fetch'll succeed */$this->sync
Hronized (function () {$this->notify ();
});
Echo ' Chr (10); /* Wait is finished with the stream */$this->synchronized (function () {$this
->wait ();
});
Echo ' Chr (10);
} echo ' 0 '. chr (10);
$thread = new fetching ();
echo ' 1 '. chr (10);
$thread->start (); Sleep (1);
It's not working properly with this added, it's weird. Echo ' 2 ' Chr (10);
$thread->synchronized (function ($me) {echo ' 3 '. chr (10);
$me->wait ();
Echo ' 4 '. chr (10);
}, $thread);
Echo ' 5 '. chr (10); * * 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": Var_dump (Unserialize ($fetched));
Break
Default:var_dump ($fetched);
printf ("\ n"); }/* Notify the thread so it can destroy resource/$thread->synchronized (function ($me) {$me->notify ()
;
}, $thread); ?>/usr/local/php-zts/bin/php fetch.php Results: 0 1 2 3 6 7 8 9 4 5 $thread->sym:int (10245) $thread->arr: Array (3) {[0]=> string (1) "1" [1]=> string (1) "2" [2]=> string (1) "3"} $thread->obj:object (Te Stobject) #2 (1) {["Val"]=> string (7) "TestVal"} $thread->objs:object (Testobject) #2 (1) {["Val"]=> s Tring (7) "TestVal"} $thread->res:resource (3) of type (stream) 11