php cli配置文件问题分析
这篇文章主要介绍了php cli配置文件问题分析,需要的朋友可以参考下
引言
今天在教别人使用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