在一台處理網絡支付的服務器遷移的時候,發現不能支付。
PHP環境:
PHP版本為5.3.3
系統為Red Hat 4.1.2-54
查看apache的錯誤日志,發現是加密文件中一個函數bcmul()報錯:
復制代碼 代碼如下:
PHP Fatal error: Call to undefined function bcmul() in /php_rsa.php on line xxx
解決辦法:
使用如下命令:
復制代碼 代碼如下:yum install php-bcmath
就安裝好了。
如果出現下面這種情況:
復制代碼 代碼如下:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.yun-idc.com
* extras: mirrors.yun-idc.com
* rpmforge: ftp.riken.jp
* updates: mirrors.yun-idc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-bcmath.x86_64 0:5.1.6-40.el5_9 set to be updated
--> Processing Dependency: php-common = 5.1.6-40.el5_9 for package: php-bcmath
--> Running transaction check
---> Package php-common.x86_64 0:5.1.6-40.el5_9 set to be updated
--> Processing Conflict: php53-common conflicts php-common
--> Finished Dependency Resolution
php53-common-5.3.3-13.el5_9.1.x86_64 from installed has depsolving problems
--> php53-common conflicts with php-common
Error: php53-common conflicts with php-common
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
就需要使用yum update 之後再yum install php53-bcmath就好了
順便了解了一下,bcmath這個函數是PHP數學擴展中的一個。可以使用 bcscale() 來設置全局默認的小數位數,具體用法如下:
復制代碼 代碼如下:
string bcmul ( string $left_operand , string $right_operand [, int $scale ] )
例子:
復制代碼 代碼如下:
<?php
echo bcmul('1.34747474747', '35', 3); // 47.161
echo bcmul('2', '4'); // 8
?>
此函數在php.ini中的選項:
復制代碼 代碼如下:
[bcmath]
; Number of decimal digits for all bcmath functions.
; http://www.php.net/manual/en/bc.configuration.php#ini.bcmath.scale
bcmath.scale = 0