|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
理解动态语言的概念,运做机制,熟悉PHP语法情况CentOS6.364bit,php5.4.5pthreads必要线程平安情况,下载php的安装包,解压:tarzxvfphp-5.4.5.tar.gz//名字是否是这个我不断定,本人往下载安装:./configure--enable-zts--prefix=/usr/local/php-ztsmakemakeinstall了局就把线程安装版的php安装到了/usr/local/php-zts,今朝我不懂得开启线程平安究竟会带来甚么影响,以是,就弄两个测试版本。下载和安装pthreads:tarzxvfpthreadscdpthreads-0.0.45//本文的是第一个stable版本/usr/local/php-zts/bin/phpize./configure--with-php-config=/usr/local/php-zts/bin/php-configmakemakeinstall/usr/local/php-zts/bin/php-igrep"php.ini"找出php.ini的地位,修正它把ext=pthreads.so到场进进出来,由于我本来就有php,如今新装的php.ini文件不存在我就考了一个已往……pthreads-0.0.45/examples目次下有些示例文件,比文档有效,在线文档基本不克不及申明成绩,我修正了一个,实行了一下:- <?php/**Sharingsymbols101*@NOTEThread::fetchwasneverincludedinareleaseandwassuperceededbyobjecthandlers*pthreadsallowsreadaccesstothreaddatafromanycontextpthreadsallowswriteaccesstothreaddatafromanycontextcarryonreading...workinprogress...*/classTestObject{public$val;}classFetchingextendsThread{publicfunctionrun(){/**ofcourse...*/$this->sym=10245;$this->arr=array("1","2","3");echo6.chr(10);/**objectsdowork,nopreparationneeded...*read/writeobjectsisntfinalized..*sodothedancetomakeitwork...*/$obj=newTestObject();$obj->val="testval";$this->obj=$obj;echo7.chr(10);/**willalwayswork*/$this->objs=serialize($this->obj);echo8.chr(10);/**nooooooo*/$this->res=fopen("php://stdout","w");echo9.chr(10);/**tellthewaitingprocesswehavecreatedsymbolsandfetchwillsucceed*/$this->synchronized(function(){$this->notify();});echo10.chr(10);/*waitfortheprocesstobefinishedwiththestream*/$this->synchronized(function(){$this->wait();});echo11.chr(10);}}echo0.chr(10);$thread=newFetching();echo1.chr(10);$thread->start();//sleep(1);加了这个就不克不及一般事情,真奇异echo2.chr(10);$thread->synchronized(function($me){echo3.chr(10);$me->wait();echo4.chr(10);},$thread);echo5.chr(10);/**wejustgotnotifiedthattherearesymbolswaiting*/foreach(array("sym","arr","obj","objs","res")as$symbol){printf("$thread->%s:",$symbol);$fetched=$thread->$symbol;if($fetched){switch($symbol){/**manualunserialize*/case"objs":var_dump(unserialize($fetched));break;default:var_dump($fetched);}}printf("
- ");}/*notifythethreadsoitcandestroyresource*/$thread->synchronized(function($me){$me->notify();},$thread);?>/usr/local/php-zts/bin/phpFetch.php了局:012367891045$thread->sym:int(10245)$thread->arr:array(3){[0]=>string(1)"1"[1]=>string(1)"2"[2]=>string(1)"3"}$thread->obj:object(TestObject)#2(1){["val"]=>string(7)"testval"}$thread->objs:object(TestObject)#2(1){["val"]=>string(7)"testval"}$thread->res:resource(3)oftype(stream)11
复制代码 大家如果能懂得“熟能生巧”的道理也就明白了这并不是浪费时间,同时这也可以减轻板主的负担,让他们有时间去处理更难的问题。 |
|