程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> php cli配置文件問題分析

php cli配置文件問題分析

編輯:PHP綜合

引言

今天在教別人使用protobuf的時候,無意中發現了一個php cli模式下的詭異問題,費了老半天的找到解決方法了,這裡拿出來分享下。

問題描述

我們這邊最先引入了protobuf協議,使用的是allegro/php-protobuf這個擴展安裝的。這幾天其他同事也要用到這個,於是我將protobuf生成php類庫文件的部分放到了一個公共的位置/data/php_proto/文件夾下,裡面有這些內容,

drwsrwxr-x 2 yanruitao users 4096 10月 14 17:05 Dmp
-rwxrwxr-x 1 yanruitao users  472 10月 10 17:59 dmp.proto
drwsrwxr-x 2 yanruitao users 4096 10月 10 17:54 ProtobufCompiler
-rwxrwxr-x 1 yanruitao users 2969 3月   9 2015 protoc-php.php

後面兩個是必須的,生成pb協議實現類庫文件時會用到,前面兩個是一個簡單的例子,使用也很簡單,就像下面這樣。

php protoc-php.php -n --psr dmp.proto //-n是使用命名空間,--psr是使用psr-4標准等同事用的時候發現會報錯,

PHP Warning:  file_put_contents(pb_proto_dmp.php): failed to open stream: Permission denied in /data/php_proto/ProtobufCompiler/ProtobufParser.php on line 309

同事問我的時候我直接說,加上sudo就可以了,結果加上sudo問題更嚴重了,本來裝好的擴展程序加載不成功,經過一番排查發下有下面這麼一個問題:

$yanruitao: php -i | grep 'php.ini'
$yanruitao: sudo php -i | grep 'php.ini'

兩種用戶加載的不是同一個配置文件,普通用戶加載的是/usr/local/php/lib/php.ini,而root用戶加載的是/etc/php.ini這個文件,我看了下這兩個文件內容不一致,哈哈,好開心,趕緊把先把/etc/php.ini備份,/usr/local/php/lib/php.ini復制到/etc/php.ini,復制完了之後,我再使用的時候嚇我一跳,報了一大堆錯誤:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/web_stub_cntl.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/web_stub_cntl.so: undefined symbol: zend_new_interned_string in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/web_stub_cntl.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/web_stub_cntl.so: undefined symbol: zend_new_interned_string in Unknown on line 0
PHP Warning:  PHP Startup: test: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20090626
These options need to match
 in Unknown on line 0

Warning: PHP Startup: test: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20090626
These options need to match
 in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/protobuf.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/protobuf.so: undefined symbol: zend_new_interned_string in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/protobuf.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/protobuf.so: undefined symbol: zend_new_interned_string in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/imagick.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/imagick.so: undefined symbol: zend_new_interned_string in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/imagick.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/imagick.so: undefined symbol: zend_new_interned_string in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/data/boss/phpredis-develop/modules/redis.so' - /data/boss/phpredis-develop/modules/redis.so: undefined symbol: zend_new_interned_string in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/data/boss/phpredis-develop/modules/redis.so' - /data/boss/phpredis-develop/modules/redis.so: undefined symbol: zend_new_interned_string in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/curl.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/curl.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/fileinfo.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/fileinfo.so: cannot open shared object file: No such file or directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/fileinfo.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/fileinfo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/gd.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/gd.so: cannot open shared object file: No such file or directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/gd.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/gd.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/json.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/json.so: cannot open shared object file: No such file or directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/json.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/json.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/phar.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/phar.so: cannot open shared object file: No such file or directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/phar.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/phar.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/data/boss/phpredis-develop/modules/redis.so' - /data/boss/phpredis-develop/modules/redis.so: undefined symbol: zend_new_interned_string in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/data/boss/phpredis-develop/modules/redis.so' - /data/boss/phpredis-develop/modules/redis.so: undefined symbol: zend_new_interned_string in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/zip.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/zip.so: cannot open shared object file: No such file or directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/zip.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/zip.so: cannot open shared object file: No such file or directory in Unknown on line 0
protoc-php.php requires protobuf extension installed to run

這讓我摸不著頭腦了。

時間過去了好久,沒有發現任何突破,卻發現了一個備用的解決這個問題的方案,修改/data/php_proto/文件夾權限為0775,其他普通用戶就可以直接使用了,不用加sudo(這個是我的錯,忘記修改文件夾權限了,這也讓我發現了這個詭異的問題)

chmod -R 0775 /data/php_proto
看了報的這些錯誤,大部分都是擴展的問題,有的是擴展加載不成功,有的是擴展不存在,我就納悶了,為什麼普通用戶可以,root用戶就不可以。

看到root用戶php -i的時候,配置文件的地方跟非root用戶有不一致的地方:

//非root

Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)

//root
Scan this dir for additional .ini files => /etc/php.d
Additional .ini files parsed => /etc/php.d/curl.ini,
......
命名加載的是一樣的配置文件怎麼加載之後的內容就不一樣呢?
搜了半天,知道了報的錯裡面有部分是跟這個有關系的,但是這個在哪裡修改搜了老久也沒有搜到。

忽然想到root用戶和非root用戶使用的php可執行文件是不一致的

root => /usr/bin/php
非root => /usr/local/bin/php

嘗試著對這兩個文件使用了php -v,結果下了我一跳,root用戶的版本是5.3.3,非root用戶是5.4.6,呵呵,我就呵呵了,誰部署的環境~,坑人啊。

嘗試著將原有/usr/bin/php備份後,復制/usr/local/bin/php過來覆蓋掉,在使用php -v發現版本一致了,也不報錯了,再次去執行php protoc-php.php -n --psr dmp.proto,發現all is well,至此問題解決。

糾結了半天,結果就是版本的問題。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved