Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How linux installs php thread extensions

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to install php thread extensions in linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how linux installs php thread extensions".

Linux installs the php thread extension: 1, find the lnmp.conf file in the lnmp installation directory; 2, add "--enable-maintainer-zts" in the "PHP_Modules_Options"; 3, compile pthreads.

Operating environment: Ubuntu 16.04system, PHP7.1 version, DELL G3 computer

How does linux install the php thread extension?

Install the pthreads extension on PHP under Ubuntu:

Pthreads is an extension of PHP that uses multithreading. Here is no longer too much introduction, I believe that since it has been done to understand, do not understand directly look at the document.

Document address: https://www.php.net/manual/zh/book.pthreads.php

Here to talk about the installation process, some twists and turns, but also access to a lot of information, before the formal installation. Write it out and make a note for yourself, and also give your later friends a reference to step on less pits.

Installation environment

Ubuntu 16.04 LTS

Lnmp 1.4-- I'm sure a lot of people are using this.

Pthreads source code

It should be noted here that this extension was not successfully installed through pecl install pthreads. You need to download your own source code compilation and installation and can only be downloaded from the GitHub trunk branch. There seems to be something wrong with the other source code. I downloaded it from http://pecl.php.net at the beginning, but the compilation always failed. Later, it was said that there was a problem with the information. You need to download it from GitHub.

GitHub: https://github.com/krakjoe/pthreads

Configure the PHP environment

By default, everyone has installed the lnmp environment. If you haven't installed it yet, please go out and turn left to Google.

Because pthreads requires PHP to run in a thread-safe way, you need to add-- enable-maintainer-zts when compiling PHP, but the lnmp integration package is thread-safe by default.

Go to your lnmp installation directory here and find a lnmp.conf file

Add to PHP_Modules_Options-enable-maintainer-zts is just like my screenshot.

Compile PHP

For the new environment, just follow the lnmp process step by step. After installation, php is thread-safe.

In the installed lnmp environment, we can use the upgrade script provided by lnmp to upgrade the php (PS: the script does not detect the current version number, if we enter the current version number, we will reinstall PHP).

* * compile PHP manually * * enter the lnmp1.4-full/src directory (according to your actual situation). My directory is in / home/src/lnmp1.4-full/src to see if there is a compressed package for php. If you don't download one yourself.

Sudo wget http://cn2.php.net/distributions/php-7.0.20.tar.bz2tar-jxvf php-7.0.20.tar.bz2

Note: the address can be obtained from the php official website. What I give here is currently available.

Continue:

. / configure-- prefix=/usr/local/php-- with-config-file-path=/usr/local/php/etc-- with-config-file-scan-dir=/usr/local/php/conf.d-- enable-fpm-- with-fpm-user=www-- with-fpm-group=www-- enable-mysqlnd-- with-mysqli=mysqlnd-- with-pdo-mysql=mysqlnd-- with-iconv-dir-- with-freetype-dir=/usr/local/freetype-- with-jpeg-dir-- with-png-dir -- with-zlib-- with-libxml-dir=/usr-- enable-xml-- disable-rpath-- enable-bcmath-- enable-shmop-- enable-sysvsem-- enable-inline-optimization-- enable-mbregex-- enable-mbstring-- enable-intl-- enable-pcntl-- with-mcrypt-- enable-ftp-- with-gd-- enable-gd-native-ttf-- with-openssl-with-mhash-- enable-pcntl-- enable-sockets-- with-xmlrpc-- enable-zip -enable-soap-- with-gettext-- disable-fileinfo-- enable-opcache-- with-xsl-- enable-maintainer-ztsmakesudo make install

This code is extracted from lnmp1.4-full/include/php.sh, you can study it yourself.

Open phpinfo ()

Confirm that Thread Safety is enabled status.

The critical moment for compiling pthreads has come.

Put the pthreads source code package into the ext directory of the php source code, and my directory is at: lnmp1.4-full\ src\ php-7.0.19\ ext [adjust according to your own situation]

Enter the pthreads directory

Phpize./configure-with-php-config=/usr/local/php/bin/php-configmakesudo make install

The php-config path is adjusted according to its own situation. If you use the lnmp default, this is it.

At this point of execution, a prompt should appear indicating that the pthreads.so compilation was successful. If not, check the previous steps.

Configure php.ini

After the general online tutorials come here, they will say: add pthreads.so to the php.ini file and restart php-fpm.

This is a pit. If you join php.ini directly, you will find that php-fpm cannot be started, indicating that pthreads.so cannot be loaded.

Correct posture:

Make a copy of the php.ini named php-cli.ini

Put pthreads.so into php.cli.ini

Then php-m | grep pthreads to see if it has already appeared.

It's only here that it's done.

Note: pthreads do not use bug in the production environment, play with yourself, run command line tasks can. Through the final installation, you also found that it can only be run through cli. Ha ha ha ha.

Finally, there are a lot of demo to see in the windows installation pthreads package.

At this point, I believe you have a deeper understanding of "how linux installs php thread extensions". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report