How to make your PHP support pthreads multithreading

Source: Internet
Author: User
Tags mcrypt php multithreading zts
We often run into a situation where the development environment is developed under Windows, and the production environment is actually Linux. Windows will work properly, but after uploading to Linux, you won't be able to play well. Then began a round of the crazy search for reasons, and finally found that the server environment problems. At this time can only silently explode a sentence shit. Recently in the use of PHP multithreaded development of a small feature also encountered similar problems, here to record.

1, find data found php5.3 or more, and thread-safe version, only support multithreading. As a result, the PHP version is too low and is not a thread-safe version by Phpinfo (). Therefore, the first need to upgrade the PHP version, due to the use of integrated wdlinux, so direct adoption of the official Website upgrade method.

Http://www.wdlinux.cn/bbs/thread-8044-1-1.html

However, after the upgrade, Phpinfo view. Thread safety is still false and continues to find. Find PHP multithreading support, compile the need to add Configuration item --enable-maintainer-zts, so that the thread is safe (thread Safety). The thread is created without an error.

Then modify the upgrade script, add --enable-maintainer-zts, and then run the step-by-step compilation. Again Phpinfo view, the hope of the scene finally appeared.

  

#!/bin/bash# PHP 5.5 update scriptsif [!]];then ver=5.5.9else Ver=$1fidebugfile=20121212echo "THANK for Usin G UPDATE SCRIPT made by HTTP://WWW. Arefly.com & HTTP://WWW. Itbulu.com "echo" You is going to UPDATE YOUR PHP-${ver} "echo" You CAN JUST has a REST "echo" IT may take A lot of time "Echo#read-p" Press ENTER IF you really want to update "Read-p" does you really want to update? (y/n) "ynif [" $yn "= =" Y "] | | ["$yn" = = "Y"]; Then echo "PHP was now updating!" else Exitfiechoecho "-------------------------------------------------------------" echo## #yumyum install-y Libmcrypt-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel libxml2-devel zip unzip## #if [!-F PHP  -${ver}.tar.gz];then wget-c http://us1.php.net/distributions/php-${ver}.tar.gzfiif [!-F iconv_ins.sh];then wget -C http://down.wdlinux.cn/in/iconv_ins.sh SH iconv_ins.shfi## #if [-f/www/wdlinux/mysql/lib/libmysqlclient.so.18];t    hen if [-d/usr/lib64];then    libncu= "/usr/lib64" Else libncu= "/usr/lib" fi ln-sf/www/wdlinux/mysql/lib/libmysqlclient.so.18 $LIBN Cufitar zxvf php-${ver}.tar.gzcd php-${ver}if [-d/www/wdlinux/apache_php];thenecho "START CONFIGURING php on NGINX" Slee P 3make clean./configure--prefix=/www/wdlinux/apache_php-${ver}--with-config-file-path=/www/wdlinux/apache_php-$ {ver}/etc--with-iconv=/usr--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr-- Enable-xml--disable-rpath--enable-inline-optimization--with-curl--enable-mbregex--enable-mbstring--with-mcrypt =/USR--with-gd--enable-gd-native-ttf--with-openssl--with-mhash--enable-ftp--enable-sockets--enable-zip-- With-apxs2=/www/wdlinux/apache/bin/apxs--with-mysqli=/www/wdlinux/mysql/bin/mysql_config--with-pdo-mysql=/www/ Wdlinux/mysql--enable-opcache--enable-bcmath--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd- -enable-maintainer-zts[$!! = 0] && echo "no! CONFIGURE Error! TRY AGAIN OR ASK in the bbs! :("&& Exitecho" START make "Sleep 3make[$?! = 0] && echo" no! Make error! TRY AGAIN OR ASK in the bbs! :("&& Exitecho" START make INSTALL "Sleep 3make install[$?! = 0] && echo" no! Make INSTALL error! TRY AGAIN OR ASK in the bbs! :("&& exitcp php.ini-production/www/wdlinux/apache_php-${ver}/etc/php.inised-i ' S/short_open_tag = Off/ Short_open_tag = on/g '/www/wdlinux/apache_php-${ver}/etc/php.inirm-f/www/wdlinux/apache_phpln-sf/www/wdlinux/ Apache_php-${ver}/www/wdlinux/apache_phpif [!-d/www/wdlinux/apache_php-${ver}/lib/php/extensions];then mkdir-p/w Ww/wdlinux/apache_php-${ver}/lib/php/extensions/no-debug-zts-${debugfile} ln-sf/www/wdlinux/apache_php-${ver}/ Lib/php/extensions/no-debug-zts-${debugfile}/www/wdlinux/apache_php-${ver}/lib/php/extensions/ No-debug-non-zts-${debugfile}fiservice httpd restartfiif [-d/www/wdlinux/nginx_php];thenecho "START CONFIGURING php On APACHE "Sleep 3makE clean./configure--prefix=/www/wdlinux/nginx_php-${ver}--with-config-file-path=/www/wdlinux/nginx_php-${ver}/ etc--with-iconv=/usr--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr-- Enable-xml--disable-rpath--enable-inline-optimization--with-curl--enable-mbregex--enable-mbstring--with-mcrypt =/USR--with-gd--enable-gd-native-ttf--with-openssl--with-mhash--enable-ftp--enable-sockets--enable-zip-- ENABLE-FPM--with-mysqli=/www/wdlinux/mysql/bin/mysql_config--with-pdo-mysql=/www/wdlinux/mysql--with-mysql= Mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd[$?! = 0] && echo "no! CONFIGURE error! TRY AGAIN OR ASK in the bbs! :("&& Exitecho" START make "Sleep 3make[$?! = 0] && echo" no! Make error! TRY AGAIN OR ASK in the bbs! :("&& Exitecho" START make INSTALL "Sleep 3make install[$?! = 0] && echo" no! Make INSTALL error! TRY AGAIN OR ASK in the bbs! :("&& exitcp php.ini-productIon/www/wdlinux/nginx_php-${ver}/etc/php.inised-i ' S/short_open_tag = Off/short_open_tag = On/g '/www/wdlinux/nginx_ Php-${ver}/etc/php.iniservice php-fpm stoprm-f/www/wdlinux/nginx_phpln-sf/www/wdlinux/nginx_php-${ver}/www/ wdlinux/nginx_phpcp/www/wdlinux/nginx_php-${ver}/etc/php-fpm.conf.default/www/wdlinux/nginx_php-${ver}/etc/ Php-fpm.confsed-i ' S/user = Nobody/user = www/g '/www/wdlinux/nginx_php/etc/php-fpm.confsed-i ' s/group = Nobody/group = Www/g '/www/wdlinux/nginx_php/etc/php-fpm.confsed-i ' s/;p ID =/pid =/g '/www/wdlinux/nginx_php/etc/php-fpm.confcp-f Sapi/fpm/init.d.php-fpm/www/wdlinux/init.d/php-fpmchmod 755/WWW/WDLINUX/INIT.D/PHP-FPMIF [!-d/www/wdlinux/nginx_ Php-${ver}/lib/php/extensions];then mkdir-p/www/wdlinux/nginx_php-${ver}/lib/php/extensions/no-debug-zts-${ Debugfile} Ln-sf/www/wdlinux/nginx_php-${ver}/lib/php/extensions/no-debug-zts-${debugfile}/www/wdlinux/nginx_ Php-${ver}/lib/php/extensions/no-debug-non-zts-${debugfile}fificd. RM-RF phP-${VER}/RM-RF php-${ver}.tar.gzrm-rf Iconv_ins.shechoecho "--------------------- www.itbulu.com-------------------------------------"echo" PHP UPDATE finish!:D " echo "Now YOUR PHP VERSION is ${ver}!" echo "UPDATE SCRIPT made by HTTP://WWW. Arefly.com & HTTP://WWW. Itbulu.com "echo" THANK you to USING "Echoecho" WDCP (C) COPYRIGHT "Echoecho" ps:i THINK you need RESTART SERVER after UPD ATE. " echo "Ps2:remember to VISIT HTTP://WWW. Arefly.com & HTTP://WWW. itbulu.com! :D "Echo

2. Next, add the pthreads extension

PHP Extensions Download: https://github.com/krakjoe/pthreads

Installing the pthreads Extension

Unzip PTHREADS-MASTER.ZIPCD pthreads-master/usr/local/php/bin/phpize./configure? with-php-config=/usr/local/php/ Bin/php-configmakemake Install

3. Change php.ini configuration (phpinfo Loaded config File node)

Vim/usr/local/php/etc/php.ini
To add a node:

After the last compilation, you will be told a pthreads.so file path

extension= '/usr/local/php/lib/php/extensions/no-debug-zts-20121212/pthreads.so '

The above node is my machine path, you change according to your own situation

Save, exit
4. Restart Apache

/usr/local/apache/bin/httpd-k restart
5, test, directly write a PHP file, new Thread, if you can output class obj, indicating that the installation was successful.

Resources:

Http://www.wdlinux.cn/bbs/thread-8044-1-1.html
------------PHP Multithreading---------------
Http://www.thinkphp.cn/topic/22676.html
Http://www.laozuo.org/4387.html
----------Thread-Safe compilation requirements---------
Http://www.45it.com/net/201503/38547.htm

http://zyan.cc/pthreads/

  • 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.