2023年6月23日 星期五

讓PHP在HTTP下支援pcntl

最近工作上需要讓PHP在HTTP下支援pcntl。在cli的PHP是可以跑的,我也是先丟去cli處理。

但總覺得少了點什麼,於是試著讓它在http也可以跑。

弄了很久,因此記一下心得。

1、外掛so解法方式。

下載PHP tarball,在ext/pcntl下做phpize,就像這樣:

cd php-5.6.40/ext/pcntl

/usr/bin/phpize  ./configure --with-php-config=/usr/bin/php-config

./configure

make && make install

cd /usr/src/php-5.6.40/ext/pcntl

cp pcntl.so /usr/lib64/php-zts/modules/pcntl.so

cd php-zts.d/

vi 40-pcntl.ini

add this line:

extension=pcntl.so

apachectl

那個php-config試過不下沒有差,但加掛後不能執行。錯誤訊息是:

cat /var/log/php_errors.log

[22-Jun-2023 08:56:32 UTC] PHP Warning:  PHP Startup: Unable to load dynamic lib                        rary '/usr/lib64/php-zts/modules/pcntl.so' - /usr/lib64/php-zts/modules/pcntl.so : undefined symbol: executor_globals in Unknown on line 0

這個問題試了幾次都無法排除。因此換方法2。(其實也找不到怎麼解)

2、在自己編譯apache/php。
原先是在公司的電腦編,但太舊了編很久,後來在家裡的電腦裝vmware來編,快很多。然後才想起來我2019年也是這樣做的)
apache: ( httpd-2.4.57 )
./configure --prefix=/etc/httpd --enable-so --enable-ssl --enable-cgi \
--enable-rewrite --with-zlib --with-pcre \
--with-includedapr=/usr/local/apr/include/apr-1  \
--enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

make && make install 

在compile過程式,缺什麼就補什麼。
apr及apr-util要自己裝。

PHP: (5.6.40)
./configure --with-apxs2=/etc/httpd/bin/apxs --with-mysql --with-pdo-mysql --with-mysqli  --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --enable-bcmath --with-bz2 --enable-calendar --with-curl  --enable-exif   --enable-ftp  --with-gd  --with-gettext  --with-gmp  --with-iconv-dir  --with-libxml-dir  --enable-mbstring  --with-mcrypt --with-mhash --with-mysql --with-mysqli --enable-mysqlnd --with-openssl --with-pcre-dir --enable-pcntl --with-pdo-mysql --with-pdo-pgsql --with-recode --enable-shmop --with-libxml-dir --with-snmp --enable-soap --enable-sockets --enable-sysvmsg --with-tidy --enable-wddx  --with-xsl --enable-zip --with-zlib --enable-maintainer-zts

因為有裝intl就要裝icu,但icu不管手動或系統自己的在PHP 在make時都不會過,最後索性不裝intl了 (intl是因為本來的PHP有,所以我才比照裝的)

另外由於我的apache有支援mpm,所以PHP就要enable zts。

然後一樣make && make install (make test會花很多時間,讓我重選我是不會去做的)

編完後,把檔案丟到server上取代原先的libphp5.so就好了 (舊的libphph5.so記得要備份)。
scp /usr/src/php-5.6.40/libs/libphp5.so 到伺服器的正確位置
在伺服器上apachectl應該就有了,用phpinfo看一下。

可惜還是失敗,看來要重新想辦法...

目前的錯誤訊息是:
PHP Fatal error:  Call to undefined function pcntl_fork()

似乎回到原點,但至少我知道哪些方法不可行了。

3、最後把方法1及方法2結合。
在vmware上編譯pnctl
cd /usr/src/php-5.6.40/ext/pcntl
phpize
./configure --with-php-config=/usr/local/bin/php-config --enable-pcntl
make 
make install
最後把modules/pnctl.so丟去伺服器上,終於搞定了。驗證如下:


接著我發現。他在網頁沒有辦法跑...那我這幾天是在忙什麼的 XD



沒有留言:

張貼留言