PHP to turn on multithreaded extensions

Source: Internet
Author: User
Tags phpinfo

PHP supports multi-threaded pthreads extensions starting from 5.3 and supports both Windows and Linux.

Pthreads can implement multitasking or asynchronous execution, which provides the complete set of tools required to create multithreaded applications, which are not installed by default.


Installation

Window System : http://windows.php.net/downloads/pecl/releases/pthreads/

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/8D/92/wKioL1iifiuSqZIpAAUcjb9pxvg744.jpg "title=" Qq20170214114826.jpg "alt=" Wkiol1iifiusqzipaaucjb9pxvg744.jpg "/>

Before installation, you need to confirm the PHP version and installation number, you can use Phpinfo (); Architecture is the current number of installed bits. Official PHP is 32-bit (64-bit compatible) in both 5.6 and previous versions, so PHP5 can download the 32-bit pthreads extension directly.

Note: 3.0 version and above for PHP7 dedicated, 3.0 version below for PHP5 dedicated.

Here is an example of PHP5.5 (32-bit) installation:

  1. Select the 2.0.9 version directory

    650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/8D/94/wKiom1iif0mA7Pz6AATZcO-lTcc312.jpg "title=" Qq20170214114826.jpg "alt=" Wkiom1iif0ma7pz6aatzco-ltcc312.jpg "/>

  2. Download the Php_pthreads-2.0.9-5.5-ts-vc11-x86.zip package and unzip it

    Note : The package name rule already contains the version +php version of Pthreads and the VC version of the underlying compilation, so you can follow this rule to find the download.

    650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/8D/95/wKiom1iiiOfyX3KbAAPXJypeZdw408.jpg "title=" Qq20170214114826.jpg "alt=" Wkiom1iiiofyx3kbaapxjypezdw408.jpg "/>

  3. Copy the Php_pthreads.dll to the PHP extension directory. Copy PthreadVC2.dll to PHP installation root and Apache installation bin directory)

  4. Open php.ini config file, add extension Extension=php_pthreads.dll Save and exit, restart server

  5. Write code tests.

<?phpclass Thread_test extends Thread {public function run () {var_dump ($this); }} $thread = new Thread_test (); $thread->start ();

No error is installed successfully, if there is an error indicating that no extension can be phpinfo (); see if the extension installs or checks whether the configuration file is modified incorrectly.



Linux system under : Http://pecl.php.net/package/pthreads

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/8D/95/wKiom1iijqqjJAkuAAmmz8pKTIU159.jpg "title=" Qq20170214114826.jpg "alt=" Wkiom1iijqqjjakuaammz8pktiu159.jpg "/>

Go to the PHP installation bin directory to execute the command:

sudo./pecl Install pthread-2.0.9

If the installation fails, try installing the lower version, you need to modify the php.ini file after the installation succeeds, and add extension=pthreads.so to open the pthreads extension.

The test is similar to window.


Application

Detailed instructions are available in the official documentation for the PHP manual >> function Reference >> Process Control Extensions in the documentation >> Pthreads

Note: PHP Resource types (many extensions or functions in PHP that use the Resource resource type are not specifically designed for multithreaded scenarios) there are many problems with sharing in multiple threads, and most resource types cannot be shared, such as database connections, file resources, etc., only socket,mysqli Such a small number of resource types can be shared!


Many examples can be viewed on GitHub: the https://www.github.com/krakjoe/pthreads examples directory.

This article is from the "gangbusters" blog, make sure to keep this source http://php2012web.blog.51cto.com/5585213/1897614

PHP to turn on multithreaded extensions

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.