PHP multithreaded Extensions (serious threads) Pthreads installation _php Tutorial

Source: Internet
Author: User
Environment CentOS 6.3 64bit,php 5.4.5 pthreads requires a thread-safe environment, download PHP installation package, unzip: Tar zxvf php-5.4.5.tar.gz//name is not this I'm not sure, go to download the installation yourself:./configur E--enable-zts--prefix=/usr/local/php-zts make made install installs the thread-installed version of PHP into the/usr/local/php-zts, At the moment I don't know what the impact of thread safety will be, so get two beta versions. Download and install Pthreads:tar zxvf pthreads CD pthreads-0.0.45//This article is the first stable version/usr/local/php-zts/bin/phpize./configure-- With-php-config=/usr/local/php-zts/bin/php-configmakemake install/usr/local/php-zts/bin/php-i|grep "PHP.ini" Find out the location of the php.ini, modify it to add ext=pthreads.so to enter, because I originally have PHP, and now the newly installed php.ini file does not exist I took a test of the past ... some sample files under the Pthreads-0.0.45/examples directory , which is more useful than a document, the online documentation simply does not explain the problem, and I modified one to perform a bit:
 
 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 does the dance to make it work ... */$obj = new Testobject ();          $obj->val = "TestVal";          $this->obj = $obj;          Echo ' 7 '. chr (10);          /* * Always work */$this->OBJS = serialize ($this->obj);          Echo ' 8 '. chr (10);          /* * nooooooo */$this->res = fopen ("Php://stdout", "w");          Echo ' 9 '. chr (10); /* The waiting process we have created symbols and fetch would succeed */$this->synchro          Nized (function () {$this->notify ();          });          Echo '. chr (10);        /* Wait for the process to is finished with the stream */$this->synchronized (function () {      $this->wait ();          });      Echo ' one '. chr (10);  }} Echo ' 0 '. chr (10);  $thread = new fetching ();  echo ' 1 '. chr (10);  $thread->start (); Sleep (1);  It's strange to add this to work. 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 is symbols waiting */foreach (Array ("Sym", "arr", "obj", "Objs", "res") as $symbol)         {printf ("\ $thread->%s:", $symbol);      $fetched = $thread $symbol; if ($fetched) {switch ($symbol) {/* * manual unserialize */CAs              E "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); ? &GT  /usr/local/php-zts/bin/php fetch.php Result: 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:r  Esource (3) of type (stream) 11

http://www.bkjia.com/PHPjc/532685.html www.bkjia.com true http://www.bkjia.com/PHPjc/532685.html techarticle Environment CentOS 6.3 64bit,php 5.4.5 pthreads requires a thread-safe environment, download PHP installation package, unzip: Tar zxvf php-5.4.5.tar.gz//name is not this I'm not sure, go download it myself ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.