contents、soap无法使用的处理

最近新安装了Fedora15,但是配置好PHP开发环境(php+nginx+MySQL)后,发现本机的file_get_contents函数和soap相关的函数不能正常使用,请求远程地址都返回空字符串,今天终于解决了,将过程记录如下:

调用soap的时候返回:

Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xx.xx.xx.xx/WS/WS.asmx?WSDL' : Start tag expected, '<' not found

使用file_getcontents函数时返回空字符串。

分析可能是因为selinux的原因

网上资料说是SELinux 阻止 httpd 守护程序与外网 服务器沟通。

需要执行以下两条命令:

#setsebool -P httpd_can_network_connect on  
#setsebool -P httpd_can_network_connect on

但是命令执行后问题依然存在,而且后面发现curl函数是可以正常返回数据的,排除selinux的原因;

百度查到可能是php.ini的allow_url_fopen选项值为Off,未开启,查看了一下php.ini是On,不是这个原因。

最后在一个国外的网站上查询到可能是php本身的原因,可能是编译参数的问题:

需要在编译php时去除-with-curlwrapper,于是重新编译了一下php5,编译命令如下:

tar zxvf php-5.2.13.tar.gz
gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1
cd php-5.2.13/
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/mysql-search --with-mysqli=/usr/local/mysql-search/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install

重新启动php-fpm和nginx,问题解决。

/usr/local/webserver/php/sbin/php-fpm start

/usr/local/webserver/nginx/sbin/nginx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywwpd.html