Cuong Pham Cuong Pham - 1 year ago 71
JSON Question

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 "" > 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:

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:


But when run:

Fatal error: Call to undefined function json_encode() in /var/www/vhosts/ on line 8

Here is run link:

Check Json:


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

I sincerely appreciate your help.


Answer Source

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 is actually loaded upon a HTTP request. My bet is that it isn't.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download