Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
867 views
in Technique[技术] by (71.8m points)

php - json seem enable but cannot run json_encode

My PHP version is 5.1.6 I have install Json by follow the instructions:

# yum install php-devel
# yum install php-pear
# yum install gcc
# pear install json
# cd /etc/php.d
# echo "extension=json.so" > json.ini
# service httpd restart

Now, I check that Json enabled, but I cannot run json_encode:

Check 1:

[root@69-64-69-43 ~]# php -i | grep json

Result 1:

/etc/php.d/json.ini,
json
json support => enabled
json version => 1.2.1

Check 2:

[root@69-64-69-43 ~]# php -r 'var_dump(function_exists("json_encode"));'

Result 2:

bool(true)

But when run:

Fatal error: Call to undefined function json_encode() in /var/www/vhosts/ykite.com/httpdocs/fre/json.php on line 8

Here is run link:

Check Json: http://69.64.69.43/fre/json.php

php_info(): http://69.64.69.43/fre/info.php

I was really looking and read many documents but I can not find the cause of this case.

I sincerely appreciate your help.

Cuong

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your var_dump( function_exists( 'json_encode' ) ) returns true, while your HTTP request says the function doesn't exist; there's only one explanation I can think of: CLI and HTTP requests use a different php.ini. In your phpinfo( ) document, it says that it's loading json.ini, but I don't see any other reference to JSON in there.

Check your logs to see whether or not json.so is actually loaded upon a HTTP request. My bet is that it isn't.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...